Quantcast
Channel: RegEx Return found Group IF String Does NOT start with ' - VSCode - Search/Replace - Stack Overflow
Viewing all articles
Browse latest Browse all 3

RegEx Return found Group IF String Does NOT start with ' - VSCode - Search/Replace

$
0
0

So, I did a global undoable RegEx search and replace. I forgot to include the ' in the replace. Now I need to do a search on strings that match the below. It must not start with a ' and will have | translate at the end. These are Angular translation keys - they can be all over in the template file (HTML). They always begin with {{, have | translate, and end with }}. Now the kicker is they could have spacing or line break issues (less likely but a chance). So it could be {{_ _ textToKeepAdd'To _ _ | _ _ translate _ _ }} The _ _ being spaces or a line break possibility.

Strings To Match (no beginning '):

anyText' | translate<other text or tags>{{ anyText' | translate{{  // line breakanyText' | translateanyText' | translate // line break

Strings Not To Match:

'anyText' | translate<other text or tags>{{ 'anyText' | translate'anyText' | translate

Return String Format:

'anyText' | translate

Example:

blahadskfjlksjdf' | translate = 'blahadskfjlksjdf' | translate'SkipMe' | translate = not found for replacement bc it starts with a '.And <other text or tags>{{ anyText' | translate =  <other text or tags>{{ 'anyText' | translate

Here is the code that I biffed on - '(?:\w+\.){1,3}(?=\w+'\s+\|\s+translate\b)

I am going to need a group capturing/returning in the replace.


Viewing all articles
Browse latest Browse all 3

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>