Stephan Sahm
2015-09-03 14:52:33 UTC
Dear all,
I am new to pyparsing and have the following aim:
*I want to match every line which does NOT start with "ABC".*
I got so far, that I formed an expression which matches an arbitrary line:
from pyparsing import *
line = LineStart().leaveWhitespace() + restOfLine
key = Literal("ABC")
So here are my first guesses, what to try:
parser0 = ~key + line
parser1 = ~(LineStart() + key) + line
However they respond like follows:
string = """
ABC
ABC
foo ABC
ABC
foo"""
print parser0.searchString(string)
[['foo ABC'], ['foo']]
print parser1.searchString(string)
[[' ABC'], ['foo ABC'], ['ABC'], ['foo']]
parser0 also ignores " ABC", which should be matched however.
parser1 does good here, however does not ignore the second "ABC"
what do I have to do for such a basic task to work?
Any help is highly appreciated,
thanks in advance,
best,
Stephan
I am new to pyparsing and have the following aim:
*I want to match every line which does NOT start with "ABC".*
I got so far, that I formed an expression which matches an arbitrary line:
from pyparsing import *
line = LineStart().leaveWhitespace() + restOfLine
key = Literal("ABC")
So here are my first guesses, what to try:
parser0 = ~key + line
parser1 = ~(LineStart() + key) + line
However they respond like follows:
string = """
ABC
ABC
foo ABC
ABC
foo"""
print parser0.searchString(string)
[['foo ABC'], ['foo']]
print parser1.searchString(string)
[[' ABC'], ['foo ABC'], ['ABC'], ['foo']]
parser0 also ignores " ABC", which should be matched however.
parser1 does good here, however does not ignore the second "ABC"
what do I have to do for such a basic task to work?
Any help is highly appreciated,
thanks in advance,
best,
Stephan