Jquery Remove Special Characters from String and More

How to remove special characters like $, @, % from string in jquery

You should explore Regex.

Try this:

var str = 'The student have 100% of attendance in @school';str=  str.replace(/[^\w\s]/gi, '')document.write(str);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

How to trim special characters from start & end of the html input using jQuery or JavaScript?

You can use the regex below to achieve your result:

^[-.,:'_/]+|[-.,:'_/]+$

Explanation of the above Regex:

^ - Represents the start of the test String.

| - Represents alternation.

$ - Represents end of the given test string.

[-.,:'_/]+ - Start or end of the string contains one or more of the characters mentioned.

Demo of the above regex here.

Implementation in JAVASCRIPT(JQUERY). You can modify the code accordingly.

const regex = /^[-.,:'_/]+|[-.,:'-_/]+$/gm;
const str = `bsvisbvskbvksv
nvlvnlvlv slcls
vnelvnelvnelv vnvsvnlvnl!
ocnsocnsocnosc ohoiIBIBiiwciv!
:nvkvnskvbskv
-bvksvbskvbsk sncksncks -cnscns-
--bvsjvbjvbjbvdbvkdbvkd-- vvnskvnskd --
lsvnslvnlsvnls:
Hello world
hellow WOLDF`;
//Notice in the 6th case above; only the last "-" gets replaced
const subst = ``;

// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);

console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

JQuery - Slice/Remove - Special characters from ID or class name

Using pop and split you can get new id without (スーペリアルーム) and set new id to div like below.

var  id = $('div').attr('id');var arr = id.split("-");//remove last element from arrayvar popItem = arr.pop();//change array back to string and replace , with -var result = arr.toString().replace(',','-');//Give New ID for div$('div').attr('id',result)console.log($('div').attr('id'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><div id =superior-room-(スーペリアルーム)" class="list-item">  <p>Title</p></div>

How to remove special characters from URL in jQuery?

Look into

 var sPageUrl = "http://localhost/DoSomething/Index/123#";
var number = sPageUrl.substring(sPageUrl.lastIndexOf('/') + 1).replace(/[^\w\s]/gi, '');
alert(number);

You could use regex to strip all special characters from the string

Remove all special characters except space from a string using JavaScript

You should use the string replace function, with a single regex.
Assuming by special characters, you mean anything that's not letter, here is a solution: