A
Andrew Poulos
I been given a string where I need to replace specific words surrounded
by curly brackets. For example
var str = "Hello {UN}";
and I replace {UN} with the user's name using:
var username = "Andrew";
var re = /{UN}/gi;
var newstr = str.replace(re, usersname);
Its only now that I realised that curly brackets have in fact a specific
purpose in regexp.
My question is, does it matter in this case as the content between the
curly brackets is not valid as far as the special meaning for curly
brackets in regexp goes, or does the regexp need to change to:
var re = /\{UN\}/gi;
Or is there a better way?
I did some testing and it seemed to always do the replacement.
Andrew Poulos
by curly brackets. For example
var str = "Hello {UN}";
and I replace {UN} with the user's name using:
var username = "Andrew";
var re = /{UN}/gi;
var newstr = str.replace(re, usersname);
Its only now that I realised that curly brackets have in fact a specific
purpose in regexp.
My question is, does it matter in this case as the content between the
curly brackets is not valid as far as the special meaning for curly
brackets in regexp goes, or does the regexp need to change to:
var re = /\{UN\}/gi;
Or is there a better way?
I did some testing and it seemed to always do the replacement.
Andrew Poulos