Regular expression for finding a regular expression?

后端 未结 3 1333
情歌与酒
情歌与酒 2020-12-19 05:30

Does anyone have code for finding a file that contains a regular expression? I would assume you could have two different flavors, one for BREs and one for EREs.

You

3条回答
  •  不思量自难忘°
    2020-12-19 05:39

    If you are looking specifically for files that contain only or mostly regular expressions, then statistics should tell you that a certain file contains more of that syntax than others. So you could define a set of indicators, and combine their scores into a metric that scored a file on how likely it was to be of interest. Pick a cutoff and let it go. Some indicators:

    • Existence of more than one [0-9], [A-Z], + etc
    • Existence of /foo/
    • Not a standard code file
    • Less compressible (dodgy, I know, but the compactness of regex grammar would intuitively be harder to compress than normal words)
    • etc

    But if this is just a one-shot, then you're probably best off using Chaos's answer and manually paring down the results. Is there anything in particular in the regex(es) you are looking for, that might be easier to pick up on?

提交回复
热议问题