Page 1 of 1

reg exp synatx prob

Posted: Wed Jun 30, 2004 9:48 am
by mm00re
hey to all,

can someone pls help me with this,

i am modifying a script that was generated with the Yaromat checkform plugin for dreamweaver.

the synatx i would like is values <= to format 99:59:59:24

this is the relevant snippet from the onsubmit action on the form, which i have already modified but only works in some instances

can u please explain the 0 | 1 | 0? in this syntax (0[0-9]|1[0-9]|0?[0-9]\)
i assumed it meant the MSB of the number (0) then the LSB of the number (1) or if only the MSB (0?) also tried swapping these vals but i cant figure out the synatx here

Code: Select all

'time_code','^\(0&#1111;0-9]|1&#1111;0-9]|0?&#1111;0-9]\)\:\(0&#1111;0-5]|1&#1111;0-9]|0?&#1111;0-9]\)\:\(0&#1111;0-5]|1&#1111;0-9]|0?&#1111;0-9]\)\:\(0&#1111;0-2]|1&#1111;0-4]|0?&#1111;0-9]\)\$','4','Field ''time_code'' is not valid.'
this is a snippet of the function that matches the regexp

Code: Select all

function YY_checkform() &#123;
var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
var myObj = MM_findObj(args&#1111;i].replace(/\&#1111;\d+\]/ig,""));
    myV=myObj.value;

if ((myV.length>0)&&(args&#1111;i+2]==4))&#123; // time
        var myMa=args&#1111;i+1].split("#"); var myAt=myV.match(myMa&#1111;0]);if(!myAt)&#123;addErr=true&#125;
      &#125;
&#125;

kind regards,

g00fy

Posted: Wed Jun 30, 2004 11:19 am
by feyd
can u please explain the 0 | 1 | 0? in this syntax (0[0-9]|1[0-9]|0?[0-9]\)
The first is looking for two digit numbers with a leading zero (00-09). The second is looking for two digit numbers with a leading one (10-19). While the third is looking for either single digit numbers or two digit numbers with a leading zero between zero and nine.

Posted: Wed Jun 30, 2004 9:06 pm
by mm00re
thank you

:D

regs,

g00fy

Posted: Sun Jul 04, 2004 11:26 am
by m3rajk
feyd wrote:
can u please explain the 0 | 1 | 0? in this syntax (0[0-9]|1[0-9]|0?[0-9]\)
The first is looking for two digit numbers with a leading zero (00-09). The second is looking for two digit numbers with a leading one (10-19). While the third is looking for either single digit numbers or two digit numbers with a leading zero between zero and nine.
that's a human way to think about it, but not logical as i think reg exp looks at it,

a|b is aORb

so ab|cd
is abd or acd
not ab or cd

so (0[0-9]|1[0-9]|0?[0-9]\)
is 0 followed by any number , followed by any number or none, followed by any number.

to get what you said it should be
(0[0-9])|(1[0-9])|(0?[0-9])

which reads
(0 followed by any number) or (1 followed by any number) or ( optional 0 and any number)

so i think what's given is flawed if you want it to match 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19

i haven't played with reg exps in a few months, so i could be wrong, but if i remeber right, to get more than just what's immediate on either side of a | you need ot group it with () since [] is a set and {} is the min/max repitition