Larsi
Larsi

Reputation: 4774

Regex matching a empty element

I need help with a regex matching the following.

      <xsl:choose>


    </xsl:choose>

That is an empty choose element. There might be none or many newlines or space inside.

EDIT: Sorry, was a bit unprecise. I'm trying to fix a broken autogenerated file. I'm opening the file in Visual Stuidio, and are using the Advanced Replace dialog, and using "Regular expression" option.

Thanks for any help

Larsi

Upvotes: 1

Views: 327

Answers (2)

jensgram
jensgram

Reputation: 31508

Untested (PHP):

~<xsl:choose>.*?</xsl:choose>~s

Using the PCRE_DOTALL modifier and a lazy quantifier.


EDIT
Sorry, I totally ignored the "empty" part. The \s character class should be used instead of the .*? part (thus, leaving the PCRE_DOTALL modifier superfluous):

~<xsl:choose>\s*</xsl:choose>~

This is already in another answer (which will get my upvote).

Upvotes: 1

Stephen Chung
Stephen Chung

Reputation: 14605

<xsl:choose>\s*</xsl:choose>

Only white-space between the tags are matched. If the tag has anything inside, it won't be matched.

Upvotes: 1

Related Questions