note
ninja-joe
Here's a simple modification to the example code that will show what the regex matched when you typed it in:
<code>
#!/usr/bin/perl
while(<>) {
chomp; # chomp so this next output is pretty.
# newlines aren't discarded when you <>
print "\"$1\" was matched out of \"$_\"" if m/(your_pattern)/;
}
</code>
Be sure to include the parenthesis around the entire regex that way it will save what it matches in $1.<br><br>
Do recall that while the regex operators are greedy by default you can suffix them with ? and they'll go to nongreedy.
An example:
<code>
#!/usr/bin/perl
while(<>) {
chomp;
print "\"$1\" was matched out of \"$_\"\n" if m/(\w{5}?)/;
}
</code>
This will match "mywor" out of "myword"<br><br>
Have fun regexing.
967
8619