问题描述:

I am trying to overcome this conversion with Regex:

abc <a href="#abc">abc</a> abc

To:

lorem <a href="#abc">abc</a> lorem

My regex is:

preg_replace('/[^<="\']*.*(abc).*[^>="\']*/i','lorem',$text)

I tried many combinations, not help to convert.

What Regex does handle that?

网友答案:

Try this:

(.*)(<a(.*?)\/a>)(.*)


group 1: abc
group :2 <a href="#abc">abc</a>
group 3: abc
网友答案:

I don't know much about regular expressions but you can try a php function

str_replace(find,replace,string,count)

E.g:

echo str_replace("world","Peter","Hello world!");

the example above will replace "world" with peter

相关阅读:
Top