triegex icon indicating copy to clipboard operation
triegex copied to clipboard

Can we build a regex-trie from regexes?

Open perkfly opened this issue 6 years ago • 1 comments

suppose there are a list of regexes:

a.*
abc.*
acc\d+efg

and a string acc4

Naively, we would have to loop through all the regexes, and find a match.

Can we build a regex-trie such that we don't have to loop over all res?

perkfly avatar Dec 15 '18 06:12 perkfly

Currently, this is not possible. However, you can manually concatenate these expressions using regex or | with the main expression:

regexes = [r'a.*', r'abc.*', r'acc\d+efg']
t = triegex.Triegex('foo', 'bar', 'baz')
result_regex = t.to_regex() + '|' + '|'.join(regexes)

Not sure if this fits your use case though.

ZhukovAlexander avatar Dec 15 '18 19:12 ZhukovAlexander