I have a text where I would like to get the first occurrence of 2 or more strings in that text.
Text:
<prod##123456_test_12345##shirt> some more text <prod##123456_test_12345##shirt>
regex:
<prod##(\d*)_(.*?)##(.*?)##(.*?)>
This will match the whole string.. But I would like to get "<prod##123456_test_12345##shirt>" only. (The first match).
I found this one:
(<)(.*?\w+.*?)(>)
It will match the first string, but I would like to keep my groups for parsing later on.
I've created a test here: http://regexr.com/v1?38pmq
I also tried Regular expression to stop at first match but I don't fully understand how it works..
(it's for PHP)
What I really want is to parse this list:
<prod##12345678##Some text here>
<prod##12345678##Some text here##Extra text>
<prod##12345678##Some text here##Extra text>
<prod##12345678_TEEXT##Some text here>
<prod##12345678_TEEXT##Some text here##Extra text>
<prod##12345678_TEEXT##Some text here##Extra text>
Is it possible to create one regex with groups for this list? 4 different ones would also be cool.
In PHP and output:
$product_reg = array ('/<prod##(\d*)_(.*?)##(.*?)##(.*?)>/',
'/<prod##(\d*)_(.*?)##(.*?)>/',
'/<prod##(\d*)##(.*?)##(.*?)>/',
'/<prod##(\d*)##(.*?)>/');
$product_rep = array ('<a href="domain.com/$1?test=$1&test2=$1_$2&$4">$3</a>',
'<a href="domain.com/$1?test=$1&test2=$1_$2">$3</a>',
'<a href="domain.com/$1?test=$3">$2</a>',
'<a href="domain.com/$1">$2</a>');
$string = preg_replace($product_reg, $product_rep, $string);