Regex Pythona, aby znaleźć białe znaki, koniec łańcucha i / lub granicę słowa

ja używamre w pythonie 2.7.5 dla wyrażenia regularnego. Próbuję to dopasowaćfoobar.com/1, `foobar.com/12, foobar.com/123lubfoobar.com/1324, alenie foobar.com/ lubfoobar.com/12345.

Mój obecny regex tofoobar\.com/\d\d?\d?\d?\W, ale będzie to pasować tylko do ciągów znaków, które nie mają słów, nie są znakami spacji, a nie ciąg znaków po żądanym łańcuchu.

Jak sprawić, by pasował do strun o dowolnej postaciz wyjątkiem dla alfanumerycznego?

Kod:

pattern1 = re.compile("foobar\.com/\d\d?\d?\d?\W")
match = pattern1.search(comment.body)
print match

Wkład:

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.

(Ciągi rozdzielone podwójną nową linią, łańcuchy # 3, 4, 7 i 9 powinny pasować.)

Wydajność:

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

questionAnswers(2)

yourAnswerToTheQuestion