[regex] How to check for non-space character?
Tim Chase
python.list at tim.thechases.com
Sat Mar 21 09:53:10 EDT 2009
Gilles Ganault wrote:
> Hello
>
> Some of the adresses are missing a space between the streetname and
> the ZIP code, eg. "123 Main Street01159 Someville"
>
> The following regex doesn't seem to work:
>
> #Check for any non-space before a five-digit number
> re_bad_address = re.compile('([^\s].)(\d{5}) ',re.I | re.S | re.M)
-------------------------------------^
>
> I also tried ([^ ].), to no avail.
--------------------^
> What is the right way to tell the Python re module to check for any
> non-space character?
It looks like it's these periods that are throwing you off. Just
remove them. For a 3rd syntax:
(\S)(\d{5})
the \S (capital, instead of "\s") is "any NON-white-space character"
-tkc
More information about the Python-list
mailing list