0

I am trying to write a Java Script function that should enclose all the special characters in the given String in a bracket like following -

Input ===> Output

123@#$, ====> 123[@][#][$][,]

Changing All the special characters to certain String [ _ in this case] is easy -

string = string.replace(/[^a-zA-Z0-9]/g,'_');

user3571396
  • 113
  • 2
  • 11
  • 1
    `.replace(/[^a-zA-Z0-9]/g,'[$&]')`. You may find some more advanced [special char regexps here](https://stackoverflow.com/questions/32311081/check-for-special-characters-in-string/32311188#32311188). – Wiktor Stribiżew Feb 16 '21 at 11:41
  • What about non-latin characters? Does é count as "special"? – evolutionxbox Feb 16 '21 at 11:42

0 Answers0