Generally lookahead assertion follows some other pattern like:
Isaac(?!Asimov)
But what does it mean when it appears at the beginning of pattern?
Here is an example (the simplename pattern is from docutils):
#!/usr/bin/env python
import re
regex = re.compile(r'(?P<simplename>(?:(?!_)\w)+(?:[-._+:](?:(?!_)\w)+)*)')
input = ['_1_2_name', '1_2_name', 'name_1_2', ':123', 'name:s:s_dd', 'name_-+.sdf']
for i in input:
match = regex.match(i)
if match:
print "MATCH: ", match.group('simplename')
else:
print "NOT MATCH: %s" % i
This regex will correctly match variable names that don't start with _, but it doesn't work when using libpcre to run the same regex. Python will not match "_1_2_name" but libpcre will match it and get "1_2_name" as a result.
I guess Python matches the position of beginning but libpcre doesn't. What is the difference between Python and PCRE? What is the equivalent pattern using PCRE?