1

If I wanted to match words ending with at and I use .{1,2} to specify that there can be 1 or 2 characters before at, how can I exclude the whitespace character?

This code

atRegex = re.compile(r'.{1,2}at')
atRegex.findall('The cat in the hat sat on the flat mat.)

will return

[' cat', ' hat', ' sat', 'flat', ' mat']

Can I somehow incorporate my own class that excludes the space character (for example [^ ] ) into the code?

Wiktor Stribiżew
  • 484,719
  • 26
  • 302
  • 397

0 Answers0