Simple regex with whitespaces

mathieu.malaterre at mathieu.malaterre at
Mon Sep 11 05:36:44 CEST 2006


  I cannot figure out a way to find a regular expression that would
match one and only one of these two strings:

s1 = '                              how are you'
s2 = '    hello world               how are you'

  All I could come up with was:
patt = re.compile('^[ ]*([A-Za-z]+)[  ]+([A-Za-z]+)$')

  Which of course does not work. I cannot express the fact: sentence
have 0 or 1 whitespace, separation of group have two or more

Any suggestion ? Thanks a bunch !

More information about the Python-list mailing list