Answer the question
In order to leave comments, you need to log in
Why does the expression "fire"?
Program in Python.
line='/link/abcd' pattern='/link/abcd(\/.*)?' m=re.match(pattern,line)
Answer the question
In order to leave comments, you need to log in
You have an extra backslash in "\" and the string is not raw. In short, it is correct to write like this:
The tail slash is not required, but if it is, any characters in any number, including zero, are allowed after it.
import re
line='/link/abcd/fdfs'
pattern='/link/abcd(\/.*)$'
m=re.match(pattern,line)
if (m):
print "Okay"
else:
print "WTF????"
import re
line='/link/abcd'
pattern='^/link/(abcd)/(.*)$'
m=re.match(pattern,line)
if (m):
print "Okay"
else:
print "WTF????"
Works because of what? at the end (i.e. the part in brackets is optional). What you want is done with the regex
/link/abcd(/.*)?$
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question