iMath wrote:
> I only know the dollar sign ($) will match a pattern from the
> end of a string,but which method does it work with ,re.match() or
> re.search() ?
Why not try it out in the interactive interpreter? Here's the "deluxe
version":
>>> def demo(pattern="mid$", texts=["start mid end", "start mid", "mid end",
"mid"], matchers=[re.match, re.search]):
... print "pattern:", pattern
... for text in texts:
... for matcher in matchers:
... name = matcher.__name__
... print u"\N{CHECK MARK}" + name if matcher(pattern,
text) else (" "*(len(name)+1)),
... print repr(text)
...
>>> demo()
pattern: mid$
'start mid end'
✓search 'start mid'
'mid end'
✓match ✓search 'mid'
--
http://mail.python.org/mailman/listinfo/python-list