regular expression - matches

Simon Forman rogue_pedro at yahoo.com
Fri Jul 21 10:17:47 EDT 2006


abcd wrote:
> how can i determine if a given character sequence matches my regex,
> completely?
>
> in java for example I can do,
> Pattern.compile(regex).matcher(input).matches()
>
> this returns True/False whether or not input matches the regex
> completely.
>
> is there a matches in python?

Yes.  It's called match and it's in the re module
(http://docs.python.org/lib/module-re.html)

Python's re.match() matches from the start of the string, so if you
want to ensure that the whole string matches completely you'll probably
want to end your re pattern with the "$" character (depending on what
the rest of your pattern matches.)

HTH,
~Simon




More information about the Python-list mailing list