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 expresion that should select matching text but escape everything between ><

I have a lot of files where i have something similar

<span translate>textTo.translate</span>

What need to look like is

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

<span>{{ $t("textTo.translate") }}</span>

What i do now is find all occurrences of span translate> and replace all with span>{{ $t(" and then go thru file and finish step by step

Is there any regex that i could use in replace all to achieve this?

What i managed to do is to select all (span translate>)[^<>]+(?=<) but i cannot find replacement regex

>Solution :

You can use

Find: <span\s+translate>([^<>]+)<
Replace: <span>{{ $t("$1") }}<

See the regex demo.

Details:

  • <span\s+translate> – a <span string, one or more whitespaces and then a translate> string
  • ([^<>]+) – Group 1 ($1 refers to this group value): one or more chars other than < and >
  • < – a < char

The replacement is <span>{{ $t(" + Group 1 value + ") }}< text.

See the demo:

enter image description here

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