regex puzzle
Harvey Thomas
hst at empolis.co.uk
Wed Nov 6 09:43:59 EST 2002
Mike Brown wrote:
>
> 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? :)
>
Why do you need a regex, or is there something you've missed out. As stated above, how about:
>>> [s != '\n' for s in ['', 'foo', '\n']]
[1, 1, 0]
Harvey
_____________________________________________________________________
This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.
More information about the Python-list
mailing list