Python regex string matching? Python regex string matching? python python

Python regex string matching?


re.match implicitly adds ^ to the start of your regex. In other words, it only matches at the start of the string.

re.search will retry at all positions.

Generally speaking, I recommend using re.search and adding ^ explicitly when you want it.

http://docs.python.org/library/re.html


the docs is clear i think.

re.match(pattern, string[, flags])ΒΆ

If zero or more characters **at the beginning of string** match the

regular expression pattern, return a corresponding MatchObject instance. Return None if the string does not match the pattern; note that this is different from a zero-length match.