\" tacked on the end." />
开发者

PHP preg_replace, need a REGEX to replace "endofentry" + number + " />"

开发者 https://www.devze.com 2023-03-03 12:52 出处:网络
I need a quick REGEX to use with preg_replace() in PHP that will remove instances of the string... \"endofentry\" + followed by any three digit number + \" />\" tacked on the end.

I need a quick REGEX to use with preg_replace() in PHP that will remove instances of the string...

"endofentry" + followed by any three digit number + " />" tacked on the end.

any help would be fantastic, thanks 开发者_开发技巧a lot!


Try this:

preg_replace('/endofentry\\d{3}\\/>/', '', 'endofentry321/> asdfa s');

Tested here


If you need to extract the three digit number, then this will work:

/(?<=endofentry)[0-9]{3}(?=\/>)/

As in:

<?php

CONST REGEX = "/(?<=endofentry)[0-9]{3}(?=\/>)/";
$stringSubject = "endofentry456/>";
preg_match(REGEX, $stringSubject, $match);
echo $match[0]; //echo's 456

?>

If you need to replace the entire string:

Update

<?php

CONST REGEX = "/\"endofentry\"[0-9]{3}\/>/";
$stringSubject = "\"endofentry\"567/>";
$stringReplace = "replace_me!";
echo preg_replace(REGEX, $stringReplace, $stringSubject); //echo's replace_me!

?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号