Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

regex avoid replace number from (.*) replacement

I want to remove part of string using start and end words in string. At the same i want to keep number appear in this range.

String:

<FORMAT=T>8</FORMAT><FORMAT=ty>45</FORMAT>

Regex:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

/(<FORMAT=T>).[^<FORMAT]*(<\/FORMAT>)/gm

output

<FORMAT=ty>45</FORMAT>

Expected output: I want keep number appear in between <FORMAT=T>...</FORMAT>

8<FORMAT=ty>45</FORMAT>

>Solution :

It looks like you want substitution (search/replace):

  • Match: <FORMAT=T>(\d+)</FORMAT> where the number between the tags is captured. \d may need to be [0-9] in some engines.
  • Substitute with \1 or $1 depending on your engine.

Demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading