check if regeular expression has results

Marc 'BlackJack' Rintsch bj_666 at
Thu Aug 9 15:04:49 CEST 2007

On Thu, 09 Aug 2007 05:58:22 -0700, shahargs 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?

Simply use an ``if`` on the result of the search or match.  If the regular
expression doesn't match `None` is returned, which is `False` in a boolean
context, otherwise a match object is returned, which is `True` in a
boolean context.

	Marc 'BlackJack' Rintsch

More information about the Python-list mailing list