I have to find any html tags with the attribute i18n in VsCode and then enclose it’s static text inside curly brackets. Like so:
<p i18n>something</p>
<p i18n>{something | odd}</p>
I’ve spent hours looking around for regex that would work and so far had no luck.
2
Answers
I think this might work (not extensively tested, and I won’t be surprised if I’ve made any mistakes):
Put this in the search field and enable regex search mode:
(<w+ i18n( w+)?>)([^<]*)(</w>)
. Put this in the replace field:$1{$3}$4
.If you want to ignore things that already have a pair of content curly braces, then use
(<w+ i18n( w+)?>)([^{][^<]*[^}])(</w>)
in the search field.If the
<p>
tags contain other tags you must capture all content till the first</p>
text.Don’t select the
<p>
tags where the content starts with a{
using(?!{)
Regex find:
(<p(?: [^>]+)? i18n(?: [^>]+)?>)(?!{)(.*?)(</p>)
Replace with:
$1{$2}$3
This does not work if you want to do it with
<div>
tags because they can contain<div>
tags. Then you need a HTML parser like Emmet.Regex find:
(<div(?: [^>]+)? i18n(?: [^>]+)?>)(?!{)
Alt_Enter
to select all occurrencesArrowRight
<div>
tag: execute command: Emmet: Balance Outward<div>
content:Ctrl+X
foobar
or could be an Emmet expression andTab
Ctrl+V
Esc