How many is a large number M of regexps?
Are the regexps complex, are you trying to capture groups (parenthesized 
subexpressions)?
Are the regexps long, and are they similar?

It may be the case that the naive approach is already the most efficient 
for your use case.
It is also possible that the combined massive regexp would suffer from 
exponential growth in memory, though I'm not sure about that.

If you were interested in only the first matching regexp, you could use 
binary search, for a total cost of log(M) massive regexp tests.

This problem sounds very interesting, please share sample data so we can 
consider sensible approaches and run benchmarks.
Cheers
Val

On Wednesday, July 27, 2016 at 10:11:35 AM UTC+2, Raj wrote:
>
> Not specific to golang. Incidentally I am using go to develop this 
> particular tool.
>
> I have a piece of text that I want to test against a large number of 
> regular expressions, where a different action is taken based on which 
> regexps successfully
> matched. The naive approach is to loop through each regexp and if matches 
> do the corresponding action and continue.
>
> I thought of combining all of the regular expressions into one massive 
> regexp, and let the regexp state machine do all the discriminating. The 
> problem with
> this is that it gives you no way to determine which regexps were the matched 
> among all.
>
> Any suggestions?
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to