Python Regex String -



Python Regex String -

homework exercise: insert regex string (just string) match number of ones , zeros (even no ones , zeros) followed 3 zeroes. illustration string,

"101000100 00101000 1010 1000"

your regex pattern should give 3 matches (using findall()):

['101000', '00101000', '1000']

my reply was:

r"[10]*1000"

but doesn't seem reply want. suggestions?

i think want this,

>>> s = "101000100 00101000 1010 1000" >>> m = re.findall(r"\b[10]*?000\b", s) >>> m ['101000', '00101000', '1000'] \b word boundary matches between word character , non-word character. [10]*? match 0 or 1 0 or more times (shortest possible match). 000 3 0's. \b , matched 0's must followed word boundary.

python regex expression

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -