-
-
Notifications
You must be signed in to change notification settings - Fork 291
Closed
Description
i have some input data like
[gog1] [G1] [gog2] [gog3] [gog4] [G2] [gog5] [G3] [gog6]
and want to find all gogs, if no G after it. so in this case i want to get gog2
and gog3
(and maybe gog6
).
looks pretty simple, rigth? but i failed :(
import pyparsing as pp
from pyparsing import *
def pyparsing_test():
# this also dont helps
# ParserElement.enable_left_recursion(force=True)
data=""" [gog1] [G1] [gog2] [gog3] [gog4] [G2] [gog5] [G3] [gog6] """
poi_type = Word(alphas).set_results_name('type')
poi = Suppress('[') + poi_type + Char(nums) + Suppress(']')
def cnd_is_type(val):
return lambda toks: toks.type==val
def cnd_is_not_type(val):
return lambda toks: toks.type!=val
poi_gog=poi('gog').add_condition(cnd_is_type('gog'))
poi_g=poi('g').add_condition(cnd_is_type('G'))
poi_not_g=poi('not_g').add_condition(cnd_is_not_type('G'))
pattern = poi_gog + ~poi_g
#WTF this finds only `gog6`, why??
pattern = poi_gog + NotAny(FollowedBy(poi_g))
#WTF same, only `gog6`
pattern = poi_gog + poi_not_g.suppress()
#WTF this works better but find only `gog2`, why not `gog3` also?
r=pattern.search_string(data)
print(data)
print('='*10)
print(r)
so my research shows that NotAny(FollowedBy(poi_g))
not works at all. what im doing wrong?
Metadata
Metadata
Assignees
Labels
No labels