N
N
Nikola_Vetrov2018-03-01 14:39:44
PHP
Nikola_Vetrov, 2018-03-01 14:39:44

How to fix regular expression?

$str = '<div class="product-desc col-md-6">
  <h1 class="product-title" id="productTitle" itemprop="name">Электродная система MCScap-NS5-2515</h1>
  <p>NS233522 L (54-60 cм)<span class="redactor-invisible-space"></span>
  </p>
  <p>NS233522<span class="redactor-invisible-space"> L/M (51-57 см)</span><br>
  </p>
  <p>NS233522<span class="redactor-invisible-space"> M (48-54 sm)<span class="redactor-invisible-space"></span><br></span>
  </p>
  <p><span class="redactor-invisible-space">NS233522 M/S (45-51 см)<span class="redactor-invisible-space"><br></span></span>
  </p>
  <p><span class="redactor-invisible-space"><span class="redactor-invisible-space">NS233522<span class="redactor-invisible-space"> S (42-48 см)<span class="redactor-invisible-space"></span><br></span></span></span>
  </p>
  <p><span class="redactor-invisible-space"><span class="redactor-invisible-space"><span class="redactor-invisible-space">NS233522 XL (60-66 см)<span class="redactor-invisible-space"><br></span></span></span></span>
  </p>
  <p><span class="redactor-invisible-space"><span class="redactor-invisible-space"><span class="redactor-invisible-space"><span class="redactor-invisible-space">NS233522 XL/L (57-63 см)<span class="redactor-invisible-space"><br></span></span></span></span></span>
  </p>
</div>';

 preg_match_all('#NS(.*?). .#is', $str, $arr3);

   print_r($arr3[1]);

the output should be
Array (
[0] => NS233522 
[1] => NS233522 
[2]=>NS233522 
[3] =>NS233522 
[4]=>NS23352 
[5] =>NS23352 )

such NS5-2515should not be
Help to solve the problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita, 2018-03-01
@Rema1ns

#(NS[\d]{3,})#
or more general
#(NS[\d]+)(?=\s)#

N
Nikola_Vetrov, 2018-03-02
@Nikola_Vetrov

help so that everything remains after the dot and dash
https://regex101.com/r/q2lVWD/9

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question