I am working on an Angular translation file and need to perform a search and replace operation in VScode for the translate key. The goal is to extract only the final key and use it in the replacement. The keys are structured with a maximum depth of 3 levels. The terms key
and keepThisInReplace
in the examples below are placeholders that will vary.
Examples of Search Strings:
'key1.keepThisInReplace1' | translate
'key1.key2.keepThisInReplace2' | translate
'key1.key2.key3.keepThisInReplace3' | translate
'anyWord.AndLevelAmount.UpTo3AtLeast.anyWordToKeep' | translate
Do not include in the search:
'../../assets/images/
'./../assets/images/
'.......
'path').join
'staging.site
etc...
The replacements should be as follows:
'keepThisInReplace1' | translate
'keepThisInReplace2' | translate
'keepThisInReplace3' | translate
'anyWordToKeep' | translate
The pattern I have attempted, which is not yet functioning properly, looks like '\w[^.].\w*.*\w*. It almost works but captures unwanted instances such as 'path').join and 'staging.site.
All the keys mentioned above are preceded by {{
. However, if I focus on {{ in my search criteria, then I also need to include it in the replacement. For example:
{{ key1.key2.keeptext | translate }}
would become {{ keeptext | translate }}