Francis B.
Francis B.

Reputation: 7208

Regular expression to find and replace a string in a xml

I'm looking for one regular expression that could match a string for three specific cases in a xml file:

  1. : Double-quotes surrounding a string.
  2. : A string surrounded by the characters greater than and Less Than.
  3. : A string surrounded by the characters ; and &.

Example:

Other possible combinations are invalid match.

  • "MyString< - Invalid match
  • ;MyString" - Invalid match

    Upvotes: 0

    Views: 1716

  • Answers (2)

    annakata
    annakata

    Reputation: 75794

    You cannot use regex to parse xml, it is not a regular grammar. Use an xml parser, seriously.

    When you're using your parser to inspect text node values then and only then you might want to use (\".*?\")|(>.*?<)|(;.*?&) but I doubt you'll find the problem is framed the same way. >MyString< is very suspicious.

    Upvotes: 2

    Brian
    Brian

    Reputation: 25834

    Try this: ("MyString")|(>MyString<)|(;MyString&)

    Upvotes: 4

    Related Questions