I am trying to use a regular expression to extract text from a large number of .txt files. I have phrases that demarcate the beginning and ending of the piece of text I want to extract. However these phrases are potentially in other parts of the document as well. The specific problem I am trying to tackle is when the beginning phrase is repeated twice without the ending phrase occurring. This leads me to collect more of the text than I want. Hopefully this specific example will help explain my problem.
When I run this code:
$x = "dog 789 cat dog dog bird cat wonder dog frog cat"; @finds = ($x =~ /((?:dog)(?:.*?)(?:cat))/g);
I end up with:
$finds[0] = dog 789 cat $finds[1] = dog dog bird cat $finds[2] = dog frog cat
How do I change my regular expression to skip over the second "dog" and end up with $finds[1] = dog bird cat?
Thanks in advance! Please excuse me if I have broken any protocols. I'm quite new to Perl and this is my first time seeking help here.
In reply to Rematching within a regular expression by jeff987
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |