Viewed   101 times

I have he following scenario:

Got an HTML template file that will be used for mailing.

Here is a reduced example:

<td>Heading 1</td>
<td>heading 2</td>
<td>Value 1</td>
<td>Value 2</td>

All I need to do is to get the HTML code inside <PRODUCT_LIST> and then repeat that code as many times as products I have on an array.

What would be the right PHP Regex code for getting/replacing this List?




Assuming <PRODUCT_LIST> tags will never be nested

preg_match_all('/<PRODUCT_LIST>(.*?)</PRODUCT_LIST>/s', $html, $matches);

//HTML array in $matches[1]
Thursday, November 10, 2022

The Arabic regex is:


Actually, ?-? is a subset of this Arabic range, so I think you can remove them from the pattern.

So, in JS it will be


See regex demo

Tuesday, October 11, 2022

I think you're searching for something like this

/ism", $search, $match);

hover, I'd suggest you to use BBcode parsers instead

To replace all spaces with &nbsp;, simply use preg_replace_callback

$text = preg_replace_callback("/
/ism", function($match) { return str_replace(" ", "&nbsp;", $match[1]); }, $search);
Wednesday, August 24, 2022

For this PHP regex:

$str = preg_replace ( '{(.)1+}', '$1', $str );
$str = preg_replace ( '{[ '-_()]}', '', $str )

In Java:

str = str.replaceAll("(.)\1+", "$1");
str = str.replaceAll("[ '-_\(\)]", "");

I suggest you to provide your input and expected output then you will get better answers on how it can be done in PHP and/or Java.

Sunday, October 9, 2022

You can use lazy quantifiers instead.

$s="foo<div>Some content is <b>bold</b>.</div>barn";

print preg_replace("/<div>.+?</div>/i", "", $s);'



UPDATE per comments:

[ghoti@pc ~]$ cat doit.php 

$text = 'text text text s html tagove
<div id="content"><b> stfu </b> ss adsda sdsa </div>
oshte text s html tagove';

print preg_replace('/<div id="content">.+?</div>/im', '', $text) .  "n";

[ghoti@pc ~]$ php doit.php 
text text text s html tagove

oshte text s html tagove
[ghoti@pc ~]$ 
Saturday, August 13, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :