skip to Main Content

I have a lot of files where i have something similar

<span translate>textTo.translate</span>

What need to look like is

<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

2

Answers


  1. Chosen as BEST ANSWER

    nvm, found answer but for some reason works only in VSCode while fails in PHPStorm.

    Find regex: span translate>([^<>]+(?=))<

    Replace regex: span>{{ $t("$1") }}<


  2. You can use

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

    See the regex demo.

    Details:

    • <spans+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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search