-2

I am trying to replace a XML file with few strings. My text can be in the following formats.

>myText<
>This is myText<
>This is myText and I need it changed<

I am trying to build a regex to catch the phrase only in the text of the XML tags so the text should be between > and < tags.

MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77
  • 2
    XML is not a regular language. Regular expressions are not the right tool for this job. [Have you tried using an XML parser instead?](https://stackoverflow.com/a/1732454/4642212) – Sebastian Simon Nov 18 '20 at 16:15
  • 1
    Can you share a larger portion of the XML file? In general you should use a parser and XPath but if regex is really the only available tool then sharing more of the file would help. – MonkeyZeus Nov 18 '20 at 16:15
  • @user4642212 Albeit comical, that linked answer is utterly useless. – MonkeyZeus Nov 18 '20 at 16:25

1 Answers1

0

Assuming you're looking for the word myText within tags and wish to capture the entire string inside the tag then try this:

(?<=>)[^<]*myText[^<]*
  • (?<=>) - look for a >
  • [^<]* - capture everything which is not <
  • myText - make sure myText exists
  • [^<]* - capture everything which is not <

You did not specify a programming language but if you're using Notepad++ then this should be compatible.

https://regex101.com/r/MPnh8J/1

MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77