Question

I would like to export some single tags that doesn't make sense in my text (exported from MS Word), such as:

<b stuff /> and <i stuff />. 

I've tried the following regex:

/<b(.*?)\/>/i

But it doesn't work when I have something like:

<i>My text</i> some other text<i class="stuff" /> my final text.

Instead of getting only the single tag, it gets everything. How could I fix this, please? The final result must be:

<i>My text</i> some other text my final text.

UPDATE: aelor's answer was the closest to the one I needed. In the end, I mixed both aelor and Mikhail's answer to get this:

/(\s?)<[ib][^>]+\/>(\s?)/

Thanks!

Was it helpful?

Solution

search <[^>]+\/>

and replace with nothing.

demo here : http://regex101.com/r/xV4xX8

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top