Very Stupid Regex question
Justin Whear via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Aug 7 10:33:42 PDT 2014
On Thu, 07 Aug 2014 10:22:37 -0700, H. S. Teoh via Digitalmars-d-learn
wrote:
>
> So basically you have a file containing regex patterns, and you want to
> find the longest match among them?
> // Longer patterns match first patterns.sort!((a,b) => a.length >
> b.length);
>
> // Build regex string regexStr = "%((%(%c%))%||%)".format
(patterns);
> auto re = regex(regexStr);
This only works if the patterns are simple literals. E.g. the pattern 'a
+' might match a longer sequence than 'aaa'. If you're out for the
longest possible match, iteratively testing each pattern is probably the
way to go.
More information about the Digitalmars-d-learn
mailing list