in reply to Re^2: Regular Expression - pattern matching
in thread Regular Expression - pattern matching
#. check the number of characters before the first "_" (underscore). #. If it's return only two characters, then get the string untill it reach the second "_"(underscore)Okay, well because you are looking for anything that is not an underscore, then a negated character class is probably the way to go. Something like this:
if (/^([^_]{2}_[^_]+)_/) { print $1; }
else if more than 2 characters then it must be a targetted patternSorry, but I don't get that. What is a "targetted pattern"?
I guess i can't able to use the "\w" (word) pattern, because it will take the whole string as a word.Yes and no. It's okay, because you are limiting it to only the first two characters with {2}. But it's probably not okay because \w will also match an underscore. So \w{2} would match something like "_a", which I'm pretty sure you don't want.
Cheers,
Darren :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Regular Expression - pattern matching
by kulls (Hermit) on Feb 22, 2006 at 12:44 UTC | |
by McDarren (Abbot) on Feb 22, 2006 at 17:55 UTC |