+4  A: 

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

Brian
victor hugo
He can replace "MyString" with whatever he wants, even another regular expression. He used MyString, so I did too.
Brian
+3  A: 

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.

annakata
I understand that this is a common refrain, but nevertheless you should change the "You cannot" part to "You should not"! ;-)
Cerebrus
I see what you're saying but on what technical grounds? You *cannot* do this with any reliability. "should not" implies that actually sometimes it's ok if you throw an unhandled exception.
annakata
In some situations a "quick and dirty" solution outweighs a "clean and polished" one. Regex is perfectly acceptable for processing text (XML formatted or not) in some situations.
patjbs
Especially if the xml might be malformed. XML parsers hate malformed XML. Regular expressions don't care.
Brian
I agree with you on this point and when I need to process an xml file I'm using an xml parser. In this case, I'm receiving a bunch of different formatted xml file (I dont know the format) and I need to convert them for another project. The only thing I know is the strings to convert can be in an attribute or in an inner text of an element. Per example, every Plant.Unit1.Current needs to be changed to Plant.Unit2.Current.
Francis B.
So, I'm not parsing any xml in this case, I'm just doing a simple search and replace.
Francis B.
Regex may be overkill and slower compared to just using the Replace member function of string.
Brian
Thanks Brian, I will check that.
Francis B.