Efficiently querying one string against multiple regexes

前端 未结 18 889
感情败类
感情败类 2020-12-12 17:16

Lets say that I have 10,000 regexes and one string and I want to find out if the string matches any of them and get all the matches. The trivial way to do it would be to jus

18条回答
  •  既然无缘
    2020-12-12 17:37

    I use Ragel with a leaving action:

    action hello {...}
    action ello {...}
    action ello2 {...}
    main := /[Hh]ello/  % hello |
            /.+ello/ % ello |
            any{0,20} "ello"  % ello2 ;
    

    The string "hello" would call the code in the action hello block, then in the action ello block and lastly in the action ello2 block.

    Their regular expressions are quite limited and the machine language is preferred instead, the braces from your example only work with the more general language.

提交回复
热议问题