Design & Devlopment Blog

Blog » jQuery » jQuery / Javascript search and remove string for Dollar sign, Bracket & other special characters

Today I had to write some code to search for a “(” in a string, and then remove it and anything past it. This seamed simple, just use the javascript search function but it DIDNT WORK!
After a google search I luckily found that you have to cancel the special charcter with “\\”  so you can use it as a normal string.

The Code

var myText = "I am a the good text ( I am the text you want to get rid of )";
var stopNumber = myText.search('\\(');
var goodText = myText.substr(0,stopNumber));

« »