Reputation: 585
Hello all and sorry to bother with another regex question... This time the problem I have is that I'm unable to match or exclude some strings out of a regexp:
Strings to compare against:
EVENT DATA
EVENT
EVENT SEC-1193 10222
EVENT META
I want this regex to match only EVENT SEC-1193 10222
and it's like this:
EVENT\s[\w'-]*\s[\w'-]*
The problem is that it matches everything... Any help in the reghell would be highly appreciated
Upvotes: 0
Views: 103
Reputation: 742
EVENT\s[\w'-]+\s[0-9]+
Seems to be a bit better. Try testing your regex's with http://gskinner.com/RegExr/ or http://regex101.com/
Upvotes: 1
Reputation: 251156
Use +
instead of *
:
>>> r = re.compile(r"EVENT\s[\w'-]+\s[\w'-]+")
>>> r.search("EVENT DATA")
>>> r.search("EVENT")
>>> r.search("EVENT SEC-1193 10222")
<_sre.SRE_Match object at 0x8e04100>
>>> r.search("EVENT META")
Upvotes: 2