How to Clean Data with Python | Codecademy
My question is in regard to the sentence in the page, I don’t understand why “moo” wouldn’t match…
An important note is that quantifiers are considered to be greedy . This means that they will match the greatest quantity of characters they possibly can. For example, the regex mo{2,4}
will match the text moooo
in the string moooo
, and not return a match of moo
, or mooo
. This is because the fixed quantifier wants to match the largest number of o
s as possible, which is 4
in the string moooo
.
Hello @devwhiz45320, weclome to the forums!
moo
wouldn’t match the regex if the regex (mo{2,4}
) was being used on a longer string, such as moooo
, because the regex wants to match as many o
's as possible, so in a string with four o
s, it’ll match all the o
's, but the string only had two o
's (moo
), then it would match that…
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.