JavaScript regular expression help

Discussion in 'JavaScript' started by Nazkyn, Mar 8, 2007.

  1. #1
    Hopefully I make sense here :)

    I have a few questions.

    An example -

    Say I have a string containing letters, numbers and characters (e.g - 'money: 200'), firstly I would like to use a regular expression to recognise a string similar to that which would be input by the user into an HTML field.

    Secondly, I would like to use a regular expression to store the numerical value (in the example; 200), now I know I can do that using parenthesis, but I only know how to do it for a single digit (/\d+/) and i'm not sure how to recall the stored value.

    Thanks in advance for any help :)

    EDIT: I've tried /money:/i (/\d*/) in a regular expression debugger, but it doesn't seem to be recognising it.

    Got it -

    /^[Money]*?: ([1-9]\d+$)/
    Code (markup):
    After some fiddling, now I just need help with calling that stored value.
     
    Nazkyn, Mar 8, 2007 IP
  2. serjio28

    serjio28 Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    var reg = /money:(\d+)/gi;
    var ret = reg.exec("Rise your money:10 every day");
    alert('money value:'+ret[1]);
    
    Code (markup):
    Does it makes help?
     
    serjio28, Mar 15, 2007 IP