Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
IWOV regex reference suggestions ?
nipper
OK, so normally I am a brute force type of guy. Instead of complex regex I write a perl script to brute force my way through a problem.
Unfortunately I cannot keep doing that, so I wanted to find out what some good reference materials might be. I am using Unix Power Tools (admittedly that is old but still really good), I also have ORA's Mastering Regular Expressions & I feel I need a stiff drink after reading that.
What do people use ? Esp specific to TS ? Since there are multiple flavors of regex, it makes it more interesting.
Somebody should put a good KB together about when to use perl regex, when extended regex, etc.
TIA
Andy
Find more posts tagged with
Comments
Migrateduser
With Perl, there is a middle ground between brute force
and a "pure" regex: the /e flag. Not all expressions
can be captured via a regular expression (e.g: recognizing
matched parens), but many things can be. What /e does is
let you make the "replacement" part of a regex arbitrary code,
-- even arbitrary function calls. Combined with the /g
flag ("do it globally"), you've got real power at your fingertips.
If you made it to the end of the ORA "Owl Book", and you
understood what you read before that stiff drink, you are
certainly not a newbie by any measure. It just comes
down to practice. My advice is to approach regexes like you
would any other language. Use it and you will understand it;
just trying to grock it by looking at a book, and you'll keep
feeling like you need a drink. I think this goes for "natural"
languages (Engish, French, Spanish) just the same as it
does for computer languages.
TeamSite's regex flavors are all very similar, and all offer
the same base regex5 "extended regular expression"
functionality. Way back when (someone help me here)
TeamSite shipped with some of the config files using
BRE (regex5 Basic Regular Expressions) rather than ERE
(regex5 Extended Regular Expressions) but this was
corrected years ago. If you know regex5 ERE, it will take
you a long, long way.
Of course, Perl lets you go even further than that with tricks
like /e /g and /ge (plus lookahead/behind assertions)
but then that's one of Perl's claims to fame. You
only need the lookahead/behind assertions very rarely,
so if you want to get something down solid, focus on
capturing parens "(...)", understanding the difference
between greedy and non-greedy ("*" versus "*?"),
when you can use OR "|", character classes "[...]",
knowing the shorthand char classes ("\s", "\w", etc),
and anchoring ("^" and "$").
Also, if you want to annotate your more involved regexes,
don't forget about the /x flag.
The most common abomination I see
("abomination vulgaris" ?) is when folks don't use " |"
and parens when they should... and instead end up
with an explosion in the number of regexes they need.