in reply to regexp: ?<=
As others have mentioned, /(?<=\t)\w+/ does not include the tab in $& which contains the text that the regular expression matched. Perhaps some code might make it a little clearer:
#!/usr/bin/perl use strict; my $string = "Testing \tthis regex"; print $string, "\n"; $string =~ /(?<=\t)\w+/; my $string1 = $&; $string =~ /\t\w+/; my $string2 = $&; print "/(?<=\\t)\w+/:\n" . $string1 . "\n"; print "/\\t\w+/:\n" . $string2 . "\n";
This is mostly useful for substitutions but hopefully my code makes it a little clearer as to what is going on. The output is as follows:
Testing this regex /(?<=\t)w+/: this /\tw+/: this
|
|---|