I am using re
in python 2.7.5 for regex. I am trying to have it match foobar.com/1
, `foobar.com/12
, foobar.com/123
, or foobar.com/1324
, but not foobar.com/
or foobar.com/12345
.
My current regex is foobar\.com/\d\d?\d?\d?\W
, but this will only match strings that have a non-word, non-whitespace, non-end-of-string character after the desired string.
How do I make it match strings with any character except for an alpha-numeric?
Code:
pattern1 = re.compile("foobar\.com/\d\d?\d?\d?\W")
match = pattern1.search(comment.body)
print match
Input:
foobar.com/12345
random text
[relevant](http://foobar.com/1319)
foobar.com/567
other comment
random comment
foobar.com/1302/
foobar.com
foobar.com/201
This is a test
You are looking at VI model 1.7 AGB Commander Shepard. Please see a store clerk to unlock a demo of this model.
Listen, if you don't have the credits just...tear me out of the terminal. Or somehting.
I sound seven percent more like Commander Shepard than any other bootleg VI copy.
SHEPHERDVI
SHEPARDVI
shepherdvi
You want help solving your problems? Get me out of this damn demo mode.
Shepard VI
Hey it works
Commander Shepard. Allicance Navy.
Commander Shepard. Allicance Navy.
TestShepard
TestShepard
Onelasttest
I sound seven percent more like Commander Shepard than any other bootleg VI copy.
(Strings separated by double new line, strings #3, 4, 7, and 9 should match.)
Output:
None
None
<_sre.SRE_Match object at 0x103f1a578>
None
None
None
<_sre.SRE_Match object at 0x103f1a578>
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None