[Javascript] Regular Exp

Shawn Milo ShawnMilo at runbox.com
Fri Jan 7 09:19:22 CST 2005


<grin>
Glad to be back.

The (?:xxx) stuff you're talking about is part of the
look-ahead or look-behind stuff. I haven't had to
use those much, so I'm not too familiar with them.
Basically, you'd use it for something like:
Match the letter q, but only if it's not immediately 
followed by a u.

Milo


> That's how you do it! :)
> 
> This grouping/replacing-parenthesis confuses me sometimes. There's 
> another way of grouping, something like (?:xxx), am I right?
> 
> Not enough regexps lately. Good to have you back.
> 
> Regards,
> H
> 
> Shawn Milo wrote:
> > Hakan and Laurent,
> > 
> > I would do this a little differently, and make
> > the decimal and the digits to the right of
> > it optional:
> > 
> > var number_re = /[0-9]+(\.[0-9]{,2})?/;
> > (untested)
> > 
> > Just to make sure I'm shooting for the
> > right goal, is the idea to have any number
> > and, optionally a decimal with no more 
> > than two decimal places?
> > 
> > Shawn
> > 
> > 
> >>Laurent,
> >>
> >>I'm a bit stressed at work now so this might be getting ugly, but you 
> >>could try this change. It should accept one or more numbers, one or no 
> >>dot and then zero to two digits. Hardcore regexp ninjas might see that 
> >>this probably also accepts 1000000000000000000000000000.33 but it's as 
> >>good as I can get it right now.
> >>
> >>var number_re = /[0-9]+\.?[0-9]{0,2}/;
> >>
> >>Regards,
> >>H
> >>
> >>Laurent Muchacho wrote:
> >>
> >>>hi Hakan,
> >>>
> >>>yes you right it match anything but number. Thanks this do put me in the
> >>>right direction but it seems a bit more complicated then I expected because
> >>>I'm checking the value on each onKeyUp event. It mean that when you start
> >>>typing eg: 1 for 100.55 it return false until you got the whole number.
> >>>
> >>>Thanks for getting back so quick and for the help provided.
> >>>
> >>>Regards
> >>>
> >>>Laurent
> >>>
> >>>-----Original Message-----
> >>>From: Hakan M (Backbase) [mailto:hakan at backbase.com]
> >>>Sent: 07 January 2005 12:26
> >>>To: [JavaScript List]
> >>>Subject: Re: [Javascript] Regular Exp
> >>>
> >>>
> >>> > var number_re = /[^0-9]/g
> >>>
> >>>This regexp rather matches anything BUT a number, unless I'm completely 
> >>>confused.
> >>>
> >>>You could try this, it's untested but should be in the right direction.
> >>>
> >>>var number_re = /[0-9]+\.[0-9]{2}/;
> >>>
> >>>Regards,
> >>>H
> >>>
> >>>Laurent Muchacho wrote:
> >>>
> >>>
> >>>>Hi Guru's
> >>>>
> >>>>I got a regex I need but can't find any good references on regex since
> >>>>netscape brought down devedge.
> >>>>
> >>>>What I need is a regex that match any number with 2 decimal 100.00 or
> >>>
> >>>43.54
> >>>
> >>>
> >>>>I call a function on the event onKeyDown on my input type text and check
> >>>
> >>>if
> >>>
> >>>
> >>>>you input a number.
> >>>>I got the logic working fine but my regex only match number and I need a
> >>>>number with 2 decimal. 
> >>>>
> >>>>this is what I got for matching only number.
> >>>>var number_re = /[^0-9]/g
> >>>>
> >>>>I tried this to match any number and a dot but it doesn't work.
> >>>>var number_re = /[^0-9]+\./g
> >>>>
> >>>>I hope you guy's can give me a hand on this and with shawn relaunching
> >>>
> >>>this
> >>>
> >>>
> >>>>list a few days ago I'm desperate about this regex skills he was talking
> >>>>about.
> >>>>
> >>>>Thanks 
> >>>>_______________________________________________
> >>>>Javascript mailing list
> >>>>Javascript at LaTech.edu
> >>>>https://lists.LaTech.edu/mailman/listinfo/javascript
> >>>>
> >>>>
> >>>
> >>>_______________________________________________
> >>>Javascript mailing list
> >>>Javascript at LaTech.edu
> >>>https://lists.LaTech.edu/mailman/listinfo/javascript
> >>>_______________________________________________
> >>>Javascript mailing list
> >>>Javascript at LaTech.edu
> >>>https://lists.LaTech.edu/mailman/listinfo/javascript
> >>>
> >>>
> >>
> >>_______________________________________________
> >>Javascript mailing list
> >>Javascript at LaTech.edu
> >>https://lists.LaTech.edu/mailman/listinfo/javascript
> >>
> > 
> > _______________________________________________
> > Javascript mailing list
> > Javascript at LaTech.edu
> > https://lists.LaTech.edu/mailman/listinfo/javascript
> > 
> > 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
> 



More information about the Javascript mailing list