Я не мог заставить это работать с отрицательным взглядом сзади ((?<!)
), но я заметил, что единственными числами, которые вы хотите установить в 0,00, являются те, которые находятся внутри тегов, начинающихся с v
.
Используя положительный взгляд назад ((?<=
), этот шаблон регулярного выражения работает:
'(?<=<v[A-Za-z]+>)([0-9]+\.[0-9]+)'
Используется на примере, который вы дали, это даст
<cProd>7898132541927</cProd>
<cEAN>7898132541927</cEAN>
<uCom>UN</uCom>
<qCom>12.0000</qCom>
<vUnCom>0.00</vUnCom>
<vProd>0.00</vProd>
<cEANTrib>7898132541927</cEANTrib>
<uTrib>UN</uTrib>
<qTrib>12.0000</qTrib>
<vUnTrib>0.00</vUnTrib>
<indTot>1</indTot>
Детали регулярного выражения:
'(?<=' Assert that the regex below can be matched, with the match ending at this position (positive lookbehind)
'<v' Match the characters “<v” literally
'[A-Za-z]' Match a single character present in the list below
A character in the range between “A” and “Z”
A character in the range between “a” and “z”
'+' Between one and unlimited times, as many times as possible, giving back as needed (greedy)
'>' Match the character “>” literally
')'
'(' Match the regular expression below and capture its match into backreference number 1
'[0-9]' Match a single character in the range between “0” and “9”
'+' Between one and unlimited times, as many times as possible, giving back as needed (greedy)
'\.' Match the character “.” literally
'[0-9]' Match a single character in the range between “0” and “9”
'+' Between one and unlimited times, as many times as possible, giving back as needed (greedy)
')'