I have the following regex in python to parse listings in text:
re.compile('(.*,?) and (.*)')
Everything works as expected, except when the re is compiled with the re.IGNORECASE flag, then the first two chars are not returned.
Output from re group 1 when compiled without the IGNORECASE flag:
the 1689 London Baptist Confession of Faith , 1742 Philadelphia Baptist Confession , the 1833 New Hampshire Baptist Confession of Faith , the Southern Baptist Convention 's Baptist Faith and Message ,
Output from re group 1 when compiled with the IGNORECASE flag:
e 1689 London Baptist Confession of Faith , 1742 Philadelphia Baptist Confession , the 1833 New Hampshire Baptist Confession of Faith , the Southern Baptist Convention 's Baptist Faith and Message ,
The documentation regarding the flag states:
Perform case-insensitive matching; expressions like [A-Z] will match lowercase letters, too. This is not affected by the current locale. To get this effect on non-ASCII Unicode characters such as ü and Ü, add the UNICODE flag.
So no hint regarding this behaviour, what could explain it or am I missing something obvious here? EDIT: As requested in the comments, the full code example (Python 3.6.5):
listing_re = re.compile('(.*,?) and (.*)')
def parse_listing(txt):
listing_search = listing_re.search(txt, re.IGNORECASE)
if listing_search:
seperated_by_comma = listing_search.group(1) # listing of expressions, seperated by ','
parts = seperated_by_comma.split(',') # split string at ','
parts.append(listing_search.group(2)) # append the single expression after 'and'
return [x.strip() for x in parts if x.strip()] # return list of stripped exressions
return list()
print(parse_listing("the 1689 London Baptist Confession of Faith , 1742 Philadelphia Baptist Confession , the 1833 New Hampshire Baptist Confession of Faith , the Southern Baptist Convention 's Baptist Faith and Message , and written church covenants"))
Code above returns wrong result, removing the re.IGNORECASE flag returns the correct result.