Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Printing out matches for two regular expressionsby choroba (Cardinal) |
on Oct 22, 2017 at 09:08 UTC ( [id://1201830]=note: print w/replies, xml ) | Need Help?? |
Why do you set $/ to a space? It reads the input file word by word and can never match the second part of the expression, it never sees the #cats together with their fin. To find all the matches on one line, use while instead of if. Finally, the second capture group populates $2, even after the vertical bar. Use a restart pattern to always start populating $1 in alternatives:
Which could be simplified to
Update: Are you sure about (\d)+? ? Have you tested it with numbers of more than one digit? You probably wanted just plain (\d+) .
In Section
Seekers of Perl Wisdom
|
|