user3142695
user3142695

Reputation: 17332

RegEx: Replacing text:s-tags

I try to replace all variations of these tags with a whitespace:

<text:s></text:s>
<text:s/>
<text:s anyattributes/>

But <text:span> shouldn't be affected.

preg_replace("/<\\/?text:s(\\s+.*?>|>)/", " ", $string);

What am I doing wrong?

Upvotes: 1

Views: 34

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

Use the below regex and replace the match with a space.

<\/?text:s\b[^<>]*>

code would be,

preg_replace("~<\/?text:s\b[^<>]*>~", " ", $string);

DEMO

\b word boundary helps you to get the job done. Since \b matches between a word and a non-word character, the above regex won't match the string <text:span> because there isn't a word boundary exists between s and p

Upvotes: 1

Related Questions