Don't ask to ask, just ask | |
PerlMonks |
Re: Most specific patternby jhourcle (Prior) |
on Jun 30, 2005 at 20:19 UTC ( [id://471461]=note: print w/replies, xml ) | Need Help?? |
I don't think that it's necessarily a function of the pattern. It's a function of the process. For instance, if there's a pattern that's more preferable to use, no matter if it's the shortest, or longest pattern, it should be tested first. In much of the work that I do, I test against the patterns that are most likely to match, and then test all of the outlying conditions that I still know how to handle. Typically, I find that longer regexes, although they might be more time consuming to match, are a more precise fit, and so I'd qualify them as 'better' in the types of processes that I deal with. A few metrics that I can think of that I might use would be:
There's probably dozens of other metrics ... I'd have to judge based on the process. Typically, I manually order things -- if regexA will match everything that regexB will match, but regexB won't match as much as regexA, I'd have to decide if there are different actions to be taken by the two, or if one outcome is preferable to the other. Oh -- and a minor nitpick. /*/ matches an asterisk. /.*/ is zero or more characters (non-newlines, unless you add modifiers).
In Section
Seekers of Perl Wisdom
|
|