Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Regex replacement not occuring

    I am trying to strip all spaces off the end of a string using the following:
    Code:
    element.value = element.value.replace(/[ ]+$/g, "");
    This only works if a single trailing space is in the element's value. Otherwise, nothing happens.
    Last edited by bauhsoj; 09-21-2005 at 05:51 AM.

  • #2
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,030
    Thanks
    0
    Thanked 247 Times in 244 Posts
    Try this:
    Code:
    String.prototype.rtrim = function()
    {
      return this.replace(/\s+$/,'');
    }
    ...
    element.value = element.value.rtrim();

  • #4
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Saw this in the FAQ just now. Sorry for posting redundant questions.

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

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    Last edited by liorean; 09-22-2005 at 04:45 AM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for clearing that up liorean.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •