...

View Full Version : Regex replacement not occuring



bauhsoj
09-21-2005, 06:40 AM
I am trying to strip all spaces off the end of a string using the following:


element.value = element.value.replace(/[ ]+$/g, "");


This only works if a single trailing space is in the element's value. Otherwise, nothing happens.

bauhsoj
09-21-2005, 06:51 AM
Well, it wasn't working five minutes ago but now it is. :(

I think the fact that I am running this on a browser in beta might have something to do with it. :(

glenngv
09-21-2005, 07:50 AM
Try this:

String.prototype.rtrim = function()
{
return this.replace(/\s+$/,'');
}
...
element.value = element.value.rtrim();

bauhsoj
09-21-2005, 08:23 PM
Saw this in the FAQ just now. Sorry for posting redundant questions. :o

What regex engine does JavaScript use? Is it PCRE 5.0+?

liorean
09-22-2005, 04:38 AM
JavaScript doesn't "use" a regex engine. Regular Expressions are a native part of the language and part of the specification. Some JavaScript Engines (e.g. KJS) use PCRE. Most (e.g. Spidermonkey, Rhino, Linear etc.) have regex integrated in the scripting engine. JScript has a shared regex engine with VBScript.

bauhsoj
09-22-2005, 04:43 PM
Thanks for clearing that up liorean. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum