regular expression problem
Karsten Hilbert
Karsten.Hilbert at gmx.net
Sun Oct 28 14:51:30 EDT 2018
Dear list members,
I cannot figure out why my regular expression does not work as I expect it to:
#---------------------------
#!/usr/bin/python
from __future__ import print_function
import re as regex
rx_works = '\$<[^<:]+?::.*?::\d*?>\$|\$<[^<:]+?::.*?::\d+-\d+>\$'
# it fails if switched around:
rx_fails = '\$<[^<:]+?::.*?::\d+-\d+>\$|\$<[^<:]+?::.*?::\d*?>\$'
line = 'junk $<match_A::options A::4>$ junk $<match_B::options B::4-5>$ junk'
print ('')
print ('line:', line)
print ('expected: $<match_A::options A::4>$')
print ('expected: $<match_B::options B::4-5>$')
print ('')
placeholders_in_line = regex.findall(rx_works, line, regex.IGNORECASE)
print('found (works):')
for ph in placeholders_in_line:
print (ph)
print ('')
placeholders_in_line = regex.findall(rx_fails, line, regex.IGNORECASE)
print('found (fails):')
for ph in placeholders_in_line:
print (ph)
#---------------------------
I am sure I simply don't see the problem ?
Thanks,
Karsten
--
GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B
More information about the Python-list
mailing list