Whenever there is an underscore "_" in the input the regex is failing
The problem here seems to be that you're taking wild guesses at how things should work rather than reading, understanding, and following the documentation. E.g., $1 will not appear out of thin air and be magically populated with the thing you were thinking about. Underscores in the input will rarely make a regex fail, but a regex that is not correctly written for the thing you want to match will not match that thing.
I suggest carefully and attentively reading perlretut, coding and trying the example patterns that are shown in it. Once you understand those, you'll be able to construct the regex that you want.
# Example for a similar case my @lines = ( "valid path /export/home/joe/data/01/", "ignore this one /var/apache/htdocs/", "valid path /usr/local/share/foobar/", "just testing /var/log/secure", "valid path /export/home/susan/recipes/" ); for (@lines){ if (m[^valid path\s+(/.*/)]){ print "$1\n"; } }
Output:
/export/home/joe/data/01/ /usr/local/share/foobar/ /export/home/susan/recipes/
In reply to Re^4: Match problem
by oko1
in thread Regex problem
by perl_mystery
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |