There’s no way you can do what you want with just three exact Matches. You can’t capture, for example, just WW
from the string WAW
in a single capturing group, whether or not using non-capturing groups.
What gives to do, however, is the following:
$string = "<table>|<tr>[<td>#VALOR#</td>]</tr>|</table>";
$regex = "#(<table>)\|(<tr>)\[<td>([^<]*)<\/td>\](<\/tr>)\|(<\/table>)#";
preg_match($regex, $string, $retorno);
$match1 = $retorno[1] . $retorno[5];
$match2 = $retorno[2] . $retorno[4];
$match3 = $retorno[3];
echo $match1 . "\n";
echo $match2 . "\n";
echo $match3 . "\n";
In the end, the variables $match1
, $match2
and $match3
will possess the values <table></table>
, <tr></tr>
and #VALOR#
, respectively, which is what you want.
And you can see the regex running on regex 101.
Considerations:
regex assumes that the only variable value in its string is "#VALUE#", which can assume any string that nay has the character <
;
regex does not handle whitespace. If the string starts with < table>
all catches would fail.
Sorry buddy, didn’t show up right what I need. It would be like this: match 1:
<table></table>
, match 2:<tr></tr>
, match 3:<td>#VALOR#</td>
.... A thousand apologies, and I appreciate the help!– Wagner