/    Sign up×
Community /Pin to ProfileBookmark

RegExp??? – newbie

Here’s a real easy question. I hope. Can someone tell me why this doesn’t work:

var stringTest = “Grendel”;
pattern = new RegExp(“n”);
stringTest.replace(pattern,’m’);
alert(stringTest);

All it “returns” is “Grendel”. It doesn’t report an error or anything, it just fails to match the ‘n’.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@GremdelauthorDec 03.2002 — Thanks Dave, works like a charm. I assume it's the same for match(...) as well.

What I really wanted it for was to strip commas and '$' out of money strings. That's easy enough but does anyone have a quick and easy way to put them back in? Don't rack your brains too hard, I already wrote a long and hard way to put them back. I was just wondering if there was a way to use regular expressions.

Thanks again.
Copy linkTweet thisAlerts:
@jboyceApr 19.2006 — select '$'||ltrim(to_char(4532.59,'999,999,999,999.99')) as amount from dual
×

Success!

Help @Gremdel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...