I'm trying to stop the anchor \ G from matching the beginning of the line. I want it to match at the end of the last regular expression match.
Given the following text:
Pig, Cow, Goat
fruit: apple, orange, peach, pear
vegetable: Carrot, Lettuce, Cellery
And this template:
(fruit:|\G)([\w]+|[\, ])
I want it to match only the words after "fruit:", but I need them to write down each word individually. If I just put + at the very end of this template, it will match all the words after “fruit:”, but it will only capture the “pear”, since each iteration + stomps on the last one.
Here is the problem. This pattern works, except that it also matches "Pig, Cow and Goat" because \ G will match the end of the last match OR the beginning of the entire line. How can I stop him from matching the beginning of the whole line?
I use PCRE in PHP, and I use Rubular.com to help me perform quick tests.
source
share