Token Capture Sequences Python Not Working Correctly
I am testing out my python grepper script. It takes multiple search patterns, and works well with regular expressions and plain text. For this test, my input.txt has the following
Solution 1:
You are currently interpreting the command line arguments as regex patterns, without replacing the placeholders %{0}
and %{1}
. You'll probably want to replace the placeholders with .*
or something similar, like so:
class Grepper(object):
def __init__(self, patterns, debug=False):
patterns= [re.sub(r'%\{\d\}', '.*', p) for p in patterns]
self.patterns = [re.compile(p) for p in patterns]
Post a Comment for "Token Capture Sequences Python Not Working Correctly"