Regex for re.match not working as expected.
Please support our Python advertiser: Programming Forums
![]() |
•
•
Posts: 2
Reputation:
Solved Threads: 0
I have the following code:
the problem I am having is that this is always evaluating to false.
python Syntax (Toggle Plain Text)
import re string = 'c:\test.doc' if re.match(r":\\[0-9a-z]", string): ##r":\\[0-9a-z]" should match ':\t' print 'true' else: print 'false'
•
•
Posts: 109
Reputation:
Solved Threads: 26
The substring "\t" in string is evaluated as a tab character. The re method match only matches at the beginning of a string. Try this:
Python Syntax (Toggle Plain Text)
import re s = r'c:\test.doc' m = re.search(r":(\\[0-9a-z])", s) if m: print m.group(1) else: print m
![]() |
Other Threads in the Python Forum
- Previous Thread: Up for a challenge? Complete coding noob in need of help to code on mobile platform
- Next Thread: win32clipboard problem
•
•
•
•
Views: 626 | Replies: 4 | Currently Viewing: 1 (0 members and 1 guests)





Linear Mode