JP Vossen on 21 Oct 2009 00:41:59 -0700 |
I have a problem with Perl and regular expressions (yeah, I know, now I have two problems:). I need to know whether a variable contains a static string or something that is a valid regular expression. One problem is that a static string is also a regular expression but I need to exclude that case, so evaluating the results of a qr//; doesn't help. To make it even more fun, the strings will sometimes contain escaped PCRE meta characters or valid literal backslashes, so I can't just m/\\/; my $regex = '\ This\sone\s*should\s+flag as a regex \ '; my $not_regex = '\ This one should not flag as a regex. \ '; The only idea I have right now would be a nightmare regex using negative lookbehinds to try to ID various unescaped PCRE meta characters. And even typing that gives me a headache. Any clues, JP ----------------------------|:::======|------------------------------- JP Vossen, CISSP |:::======| http://bashcookbook.com/ My Account, My Opinions |=========| http://www.jpsdomain.org/ ----------------------------|=========|------------------------------- "Microsoft Tax" = the additional hardware & yearly fees for the add-on software required to protect Windows from its own poorly designed and implemented self, while the overhead incidentally flattens Moore's Law. ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|