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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question js lacks of regex funcs?

    i'm attempting to get a letter appearing number in a string and have problems. firstly i tried with
    PHP Code:
    filtered=document.formname.title.value.replace(/s/,"");
    words=filtered.length
    but it didn't make the trick. as far as i know there's no a regex function that returns an array of matches or something else that helps my here. any ideas?
    p.s. yes i know the 's' in the pattern must be escaped. actually it is but the php doesn't print it.
    Last edited by madson; 05-08-2006 at 09:59 PM.

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    var arrayOfMatchesofNumbers = "a1b2c3d4e5f".match(/[0-9]/);

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Madson: There is a link to an article I wrote about regular expressions in JavaScript in my signature. You could always have a look at that.

    Demonstrating a few of the JavaScript regex handling mechanisms:
    Code:
    var
        r=/t/,
        rg=/t/g,
        s='test';
    alert([
            'r.test(s) : '+r.test(s),
            'rg.test(s) : '+rg.test(s),
            'r.exec(s) : '+r.exec(s),
            'rg.exec(s) : '+rg.exec(s),
            's.match(r) : '+s.match(r),
            's.match(rg) : '+s.match(rg),
            's.search(r) : '+s.search(r),
            's.search(rg) : '+s.search(rg),
            's.split(r) : '+s.split(r),
            's.split(rg) : '+s.split(rg),
            's.replace(r) : '+s.replace(r,'§'),
            's.replace(rg) : '+s.replace(rg,'§')].join('\n'));
    This will alert:
    Code:
    r.test(s) : true
    rg.test(s) : true
    r.exec(s) : t
    rg.exec(s) : t
    s.match(r) : t
    s.match(rg) : t,t
    s.search(r) : 0
    s.search(rg) : 0
    s.split(r) : ,es,
    s.split(rg) : ,es,
    s.replace(r) : §est
    s.replace(rg) : §es§
    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


  •  

    Posting Permissions

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