in reply to book vs. web for Perl Regex study?
I agree with others here that you should first and foremost get your hands dirty and just play with regexes. Just use a lot of capturing and print out what you just captured like so:
All you need to know here is that the parentheses capture the string that was matched and the array will contain all matched strings from this regex. The /g means "don't stop after first match, keep searching the entire string". Then play with the regex a bit. Be sure to try character groups such as [a-z], try greedy vs non-greedy:my $string = "testing, testing, 123"; my @captured = ($string=~/(testing)/g); print "captured: $_\n" for @captured;
try anchors like ^ (beginning of string) and $ (end of string). That will get you started.# match lowercase letters commas and space and get as many as possible + (greedy) $string=~/([a-z,\s]+)/; # same but non-greedy (stop as soon as you can) $string=~/([a-z,\s]+?)/;
|
|---|