Home
TeamSite
regex in JS
nipper
OK, I have to take a variable and make it a filename
So in Perl I use a statement like:
$ttile="Words letters # 450 235&$*(_@";
$title =~ s|[^A-Z0-9]||gi;
$title has all the words and numbers only, no spaces or special characters.
I have done regex in JS, but only to test =~ m|something| equivilent
How do I do substitution in JS ?
ANdy
Find more posts tagged with
Comments
brandon1
a string object has a replace method that can be used with a regular expression
var title ="Words letters # 450 235&$*(_@";
var regEx = /[^A-Z0-9]/gi;
title = title.replace(regEx,"");
Current Project: TS 6.1
Environment: Windows
jbonifaci
or if you want to do it on one line...
title = title.replace(/[^A-Z0-9]/gi,"");
~Jeff
nipper
knew it was something simple, thanks.
Andy
jbonifaci
For reference of anyone finding this thread, they can read about replace and other String methods
here
or to find out more about the RegExp object, they can go
here
.
~Jeff
brandon1
IMOP
http://www.devguru.com
jumped the shark when they redesigned their reference manual....
Better of googling it....
Current Project: TS 6.1
Environment: Windows
jbonifaci
Yes, google is always a good place to start. But when providing links for people to reference, linking to real content is better,
.
brandon1
As long as it still exists in a year.
Current Project: TS 6.1
Environment: Windows
jbonifaci
Well, if someone gets broken links, they can still google and won't be any worse off,
.