tags:

views:

53

answers:

3

Hi,

I am trying to do this regex match and replace but not able to do it.

Example

<SPAN class="one">first content here</SPAN>
<SPAN class="two">second content here </SPAN>
<SPAN class="three">one; two; three; and more.</span>
<SPAN class="four">more content here.</span>

I want to find each set of the span tags and replace with something like this

Find

<SPAN class="one">first content here</SPAN>

Change to

<one>first content here</one>

same way the the rest of the span tags.

class="one", class="two" and so on are the only key identifier which I use in the regex match expression. So if I find a span tag with these class then I want to do the replace. My main issue is that I am not able to find the occurrence of first closing tag so what it does is it finds from the start to end which is of no use. So far I have been trying to do this using notepad++ but just found that it has its limitations so any php help would be appreciated.

regards

A: 

Hi,

I am trying to do this regex match and replace but not able to do it.

Example :

first content here second content here one; two; three; and more.more content here.

I want to find each set of the span tags and replace with something like this

Find first content here Change to first content here

same way the the rest of the span tags.

class="one", class="two" and so on are the only key identifier which I use in the regex match expression. So if I find a span tag with these class then I want to do the replace. My main issue is that I am not able to find the occurrence of first closing tag so what it does is it finds from the start to end which is of no use. So far I have been trying to do this using notepad++ but just found that it has its limitations so any php help would be appreciated.

regards

gan
+2  A: 
preg_replace('/<span class="(.*?)">(.*?)<\/span>/i', '<$1>$2</$1>', $input);
Coronatus
This worked. thanks. I learn something!
gan
but there is a typo. should add a ) before the double quotes ends.
gan
A: 

Repost with [ instead of less-than-sign if you can't post < correctly.

chx