JP Vossen on 21 Oct 2009 00:41:59 -0700

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] PCRE is_a_regex?

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 Vossen, CISSP            |:::======|
My Account, My Opinions     |=========|
"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         --
Announcements -
General Discussion  --