Kaviraj       Archive       Tags

Understanding regular expression parsing

I was reading a wonderfull article on python regular expression. And I was playing with some example code.

import re

text = "aabbbaaababaab"
pattern = "abb"

re.findall(pattern, text)
# output: ['abb']
# pattern 'abb' found at index 1:3

then I got stuck with following code. I couldn’t understand why the output is the way it is.

import re

text = "aabbbaaababaab"
pattern = "ab+" # a followed by one or more b

re.findall(pattern, text)
# output: ['abbb', 'ab', 'ab', 'ab']
# wait.. Where is "abb"?

Read More

#python #regular-expression