Closed prakash-niroula closed 9 months ago
true
Interesting, it must be a glitch inside the Regular Expression:
String.prototype.replace_fr = function (target: string, replacement: string): string {
const pattern = new RegExp('(?<![\'"`])\\b' + target + '\\b(?!["\'`])', 'g');
return this.replace(pattern, replacement);
}
It's supposed to replace keywords that are not inside strings, and it works well for words like "lit".
Maybe someone who's more experienced in RegExp can look into this?
Interesting, it must be a glitch inside the Regular Expression:
String.prototype.replace_fr = function (target: string, replacement: string): string { const pattern = new RegExp('(?<![\'"`])\\b' + target + '\\b(?!["\'`])', 'g'); return this.replace(pattern, replacement); }
It's supposed to replace keywords that are not inside strings, and it works well for words like "lit".
Maybe someone who's more experienced in RegExp can look into this?
yeah it's because of regexp
I think it's because of space. " fr " is a match but "fr" isn't
This regex works well if implemented recursively :
String.prototype.replace_fr = function (target: string, replacement: string): string {
const pattern = new RegExp('^([^\'"`]+|[^\'"`]+[\'"`][^\'"`]+[\'"`][^\'"`]+)' + target,'gs')
let tmpStr = this.slice()
while ( tmpStr.match(pattern) ) {
tmpStr = tmpStr.replace(pattern, '$1' + replacement)
}
return tmpStr;
}
It's supposed to replace keywords that are not inside strings, and it works well for words like "lit".
@face-hh It doesn't
waffle("Regex check")
lit word be "hey lit x be 10 fr 10 rn " rn
waffle(word)
Produces
hey let x = 10 == 10 ;
fixed in #30
Fixed in #30
Consider this
Expected : Hey do you want this ? fr fr ! Got : Hey do you want this ? == == !