|Welcome to the Monastery|
Pattern matching when there are exception stringsby Moron (Curate)
|on Sep 21, 2005 at 12:52 UTC||Need Help??|
Moron has asked for the wisdom of the Perl Monks concerning the following question:
I have a set of search strings e.g. ALPHA, BETA, GAMMA plus a set of exceptions e.g. for ALPHA: "_ALPHA", "#ALPHA", "XL5 ALPHA" with a different set of exceptions for each search string. Note also that the search string may be any substring of one of its exceptions, not just a right substring as in this example.
I have a top directory to a tree containing years of source code and want to scan the lot and produce a report where each line is in the form:
where the text at that line in that file has met the above search criteria (i.e. matches bar the exceptions).
Without the exceptions requirement it was easy enough to recurse through the tree opening files and matching patterns against their contents - it's straightforward enough that I have to search each line multiply for the search strings.
But I seem to have a problem arranging the logic when it comes to eliminating the exceptions. For example:
"I AM ALPHA AND #ALPHA"
It contains both an exception and a non-exception so has to pass the criteria for a successful ALPHA search.
Any ideas from pattern-matching gurus would be more than welcome!
Update: here is the code so far:
Free your mind