skip to Main Content

I am trying to remove ® from a string
"My Title with Special Characters My® tag
and return
"My Title with Special Characters My tag"

Unicode points to character is ae, got to know using char.charCodeAt(0)
const regex = /[^A-Za-z0-9]/g; should remove the same.

2

Answers


  1. let x = "we want to remove ® even if it occurs twice like this®, how to remove ® from the string"
    
    console.log(x.replaceAll(/u00ae/g, ""));
    
    // we dont even need regex as there is only one value
    
    console.log(x.replaceAll("u00ae", ""));
    console.log(x.replaceAll("®", ""));
    Login or Signup to reply.
  2. If you just want to replace all "®" i would advise not to use regex at all:

    "My Title with *  ä #Special ' Characters My® tag".replaceAll("®","")
    // "My Title with *  ä #Special ' Characters My tag"
    

    if you want to replace all characters that are not ascii characters for example, use something like /[^ -~]/ where you can list additional characters you want to keep at the end of the character group: /[^ -~äüöÖÄ]/:

    "My Title with *  ä #Special ' Characters My® tag".replaceAll(/[^ -~äüöÄÜÖß]/g,"")
    // "My Title with *  ä #Special ' Characters My tag"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search