XYZZZ" or " XYZZZ" or " XYZZZ" or "

preg_match pattern matches (php)

37 views Asked by At

I have a string, such as "<span class="m-product-data-3__price-value" itemprop="price" content="143.28">XYZZZ</span>" or "<span class="m-product-data-3__price-value" itemprop="price" content="198.22">XYZZZ</span>"

I want to extract XYZZZ value with preg_match($pattern, $string, $match). But I want the value to be in $match(1) How to do it ? What pattern to use?

'<span class=\"m-product-data-3__price-value\" itemprop=\"price\" cont ent=\"(.*)\">(.*?)<'si - gives me the value in $match(2)

1

There are 1 answers

0
Anggara On

Use (?:...) for non-capturing group. So your pattern should be:

'<span class=\"m-product-data-3__price-value\" itemprop=\"price\" content=\"(?:.*?)\">(.*?)<'si

Or maybe dont use parenthesis at all:

'<span class=\"m-product-data-3__price-value\" itemprop=\"price\" content=\".*?\">(.*?)<'si