0

I'm trying to write a regex expression (or find some other easier method) to find and replace all values between the xml tags in sublime like the following:

Find value of SENDERNAME

   <SENDERNAME>TEST</SENDERNAME>

Replace value and turn into

<SENDERNAME>REPLACED<SENDERNAME>

I'm having trouble writing regex for it as I am a beginner. I need to do this for 100's of tags so I need code to replace them all. I'm not finding any tutorials or easy ways of doing it with just sublime.

Thanks in advance,

Mark

Mark
  • 445
  • 7
  • 26
  • 2
    Are you sure about `REPLACED`? Maybe `REPLACED`? Really no tutorials? Look here: [regexone.com](http://regexone.com), [regular-expressions.info](http://www.regular-expressions.info), [What does the regex mean](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean), [Learning Regular Expressions](http://stackoverflow.com/a/2759417/3832970). – Wiktor Stribiżew Jul 21 '16 at 11:30
  • What definition of "XML tag" are you using? Is it `` or `TEST`? If it's the actual tag (``), is `TEST` going to change, or will it always be the literal `TEST`, always to be replaced by the literal `REPLACED`? If you really have 100s of tags to process, you'd be **much** better off using an XML parser in the language of your choice. – MattDMo Jul 21 '16 at 12:06

2 Answers2

2

It would be easier to replace the whole tag, than to actually replace the value within. You can search for the following regex:

<SENDERNAME>.*</SENDERNAME>

and replace it with the new value

<SENDERNAME>REPLACED</SENDERNAME>
jens walter
  • 10,812
  • 2
  • 49
  • 48
1

Try this RegEx: <SENDERNAME>[^<>]*</SENDERNAME>

  • Welcome to Stack Overflow! While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – jmattheis Apr 17 '17 at 18:57