I have been writing a lot of code in both C# and Python lately... flipping back and forth between both languages. One thing I keep getting tripped up on is the terminology used in regular expression syntax, and what a "match" is.
So for my own disambiguation:
Better explained in code:
Using Regex.IsMatch() in C# to match a pattern with some text:
this prints 'Match'
Same thing, using re.match() in Python:
this prints 'No Match'
oops.. didn't get a match. What happened?
match() only checks if the regex matches at the beginning of the string, while search() will scan forward through the string for a match.
If you were expecting the pattern to match anywhere in the string, you need to use re.search() instead:
... or else you must supply a pattern that will match from the beginning of the string:
Copyright © 2006-2008 Corey Goldberg
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.