regex puzzle

Mike Brown mike at skew.org
Wed Nov 6 07:52:37 EST 2002


I need an example of a regular expression that:

- matches an empty string
- matches a non-empty string
- does NOT match a string consisting of only a linefeed

So, this test should produce [1, 1, 0]...

import re
pat = '^(.+)?$' # FIXME
[(re.search(pat, s) is not None) for s in ['', 'foo', '\n']]

Any suggestions? :)

Thanks






More information about the Python-list mailing list