-1

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)

IMSoP
  • 89,526
  • 13
  • 117
  • 169
  • I do not understand your question... Please format your code, and put the real `preg_match` you are using – pierpy Apr 08 '23 at 14:59
  • 1
    The round brackets `()` will cause a capture group.. if you don't want it, don't use it^^ – Honk der Hase Apr 08 '23 at 15:51
  • preg_match("'(.*?)<'si", "XYZZZ", $match); content="198.22" is changing... can be content="198.22", content="143.28", etc I need some mask that preg_match will ignore – Marek Korbus Apr 08 '23 at 17:05
  • $str1="XYZZZ" and $str2="XYZZZ" I need pattern for preg_match to return match(1) ->XYZZZ – Marek Korbus Apr 08 '23 at 17:12

1 Answers1

0

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
Anggara
  • 625
  • 4
  • 8