check if regeular expression has results
wpdster at gmail.com
Thu Aug 9 15:12:51 CEST 2007
On 8/9/07, shahargs at gmail.com <shahargs at gmail.com> wrote:
> I'm looking for the best way to check if regular expression return
> true (it's mean - there is a match). for example, i want "if" that
> check if this regular expression: .*born.*to.* has a match.
> What's the way to do that simply?
re.match(".*born.*to", "This is a test")
re.match(".*born.*to.*", "This test was born so that it worked too.")
(Try these at the python prompt)
The first call to 're.match()' returns 'None' which will fail an if
test. The second one returns a match object, which evaluates to TRUE
in an if test.
More information about the Python-list