user2988464
user2988464

Reputation: 3461

Python: regular expression pattern other than a comma

How can I set the regular expression pattern other than SPECIFIC CHARACTER?

import re
str = 'abc?, def/ghi'
match = re.findall(r'[anything other than ',' or \s]', str)

print(match)
['abc?', 'def/ghi']

THX!!!

Upvotes: 0

Views: 35

Answers (1)

Alfe
Alfe

Reputation: 59436

What about the straight forward

[^,]

which means exactly what you said. Did you even bother reading a regexp documentation? ;-)

For all except a comma and whitespace you can use the same approach:

[^,\s]

And to get a sequence of those use this:

[^,\s]+

Upvotes: 1

Related Questions