I have a string like foobar1, foobaz2, barbar23, nobar100 I want only foobar, foobaz, barbar, nobar and ignoring the number part.
-
2I don't think this has much to do with jQuery - that is a javascript framework for DOM manipulation. You're doing string parsing, everything you need is in the javascript language.Graham Clark– Graham Clark2011-05-25 08:37:57 +00:00Commented May 25, 2011 at 8:37
Add a comment
|
5 Answers
If you want to strip out things that are digits, a regex can do that for you:
var s = "foobar1";
s = s.replace(/\d/g, "");
alert(s);
// "foobar"
(\d is the regex class for "digit". We're replacing them with nothing.)
Note that as given, it will remove any digit anywhere in the string.