Python regex match space only

No need for special groups. Just create a regex with a space character. The space character does not have any special meaning, it just means “match a space”.

RE = re.compile(' +')

So for your case

a="rasd\nsa sd"
print(' +', a))

would give

<_sre.SRE_Match object; span=(7, 8), match=" ">

Leave a Comment