|
|
Need an expression to validate numeric digit is sequential and sort ascending(desc) ,such as 123456 , 456789 are valid .
Last post 10-15-2008, 5:13 AM by sparky. 22 replies.
-
10-09-2008, 4:38 AM |
-
sparky
-
-
-
Joined on 10-07-2008
-
-
Posts 18
-
-
|
Re: Need an expression to validate numeric digit is sequential and sort ascending(desc) ,such as 123456 , 456789 are valid .
Dear ddrudik , Thanks for your kindly advise in advance ! To be honest , There are thousands of different patterns need to be stored in database,If I write functions,there are so many, so I must validate them by regular expression . But I don't do well in regex , I need your great help , thannks ... BTW, how to compare with one of a digit string ? such as 01234A6789 , compare with A , if (A > 5) ...this expression is valid ... Best regards, Sparky
|
|
-
10-09-2008, 5:01 AM |
-
prometheuzz
-
-
-
Joined on 04-28-2008
-
-
Posts 659
-
-
|
Re: Need an expression to validate numeric digit is sequential and sort ascending(desc) ,such as 123456 , 456789 are valid .
sparky:... BTW, how to compare with one of a digit string ? such as 01234A6789 , compare with A , if (A > 5) ...this expression is valid ... Best regards, Sparky
Dear Sparky, please keep the discussion in one thread. For the question above, you have already created a new thread: please continue there. Thanks.
|
|
-
10-09-2008, 9:20 PM |
|
|
Re: Need an expression to validate numeric digit is sequential and sort ascending(desc) ,such as 123456 , 456789 are valid .
sparky: To be honest , There are thousands of different patterns need to be stored in database,If I write functions,there are so many, so I must validate them by regular expression .
I think there may be some confusion here. If I were to do this I would be storing the patterns in the database and writing my own function that interpreted the patterns, not one function for each pattern. Also I would not be storing any regex patterns in a database - the maintenance of these would be horrendous because, as you have already seen, the regex patterns needed to implement even one of your patterns is very complex. At best, can you store a simplified version of your requirements in the database and then use your code to generate a regex pattern 'on the fly'. However, you appear to still be trying to use regex's for inappropriate tasks.
At this stage I suspect that we have not seen what you are really trying to achieve: what sort of patterns are you dealing with; what are the rules that you are trying to use to validate/search the text? Please don't try to "abstract" the problem too much because, as you have seen already, talking about ABCABDABE is just confusing to everyone without a better understanding of you task. Susan
|
|
-
10-10-2008, 4:56 AM |
-
sparky
-
-
-
Joined on 10-07-2008
-
-
Posts 18
-
-
|
Re: Need an expression to validate numeric digit is sequential and sort ascending(desc) ,such as 123456 , 456789 are valid .
Dear all, Thanks for all your constructive and nice advice in advance ^)^ I will state my problem once again in more details ...all the problems we discussing is about digit and independent of letter . different letter is just stand for different digit... Question : ABC-ABD-ABE is a 9 bit numeric string( A B C D E are different dgit, C D E must be sequential and sort ascending) , just like 124125126 , 253254255 ,192193194 ,384385386 ,781782783 and so on . Many thanks and best regards, Sparky
|
|
-
10-10-2008, 5:30 AM |
-
prometheuzz
-
-
-
Joined on 04-28-2008
-
-
Posts 659
-
-
|
Re: Need an expression to validate numeric digit is sequential and sort ascending(desc) ,such as 123456 , 456789 are valid .
sparky:Dear all, Thanks for all your constructive and nice advice in advance ^)^ I will state my problem once again in more details...
sparky, let me state to you once again: this is not something that regex is good at solving. The previous "solutions" were more meant to make it clear to you that it is madness to do this with regex. Just as this "solution": ^(\d\d)\d\1((?<=0..)1|(?<=1..)2|(?<=2..)3|(?<=3..)4|(?<=4..)5|(?<=5..)6|(?<=6..)7|(?<=7..)8|(?<=8..)9)\1((?<=0..)1|(?<=1..)2|(?<=2..)3|(?<=3..)4|(?<=4..)5|(?<=5..)6|(?<=6..)7|(?<=7..)8|(?<=8..)9)$ The above will match all of your example strings: 124125126, 253254255, 192193194, 384385386, 781782783. But it will NOT match strings like this: 118119120, 779780781, etc. That is because regex treats digits not numerically, but as plain text. If you want to match 118119120, 889990991 as well, then that regex would be at least ten to twenty times as large (probably even larger) as the one I posted above, making it something that could make it's appearance in a cheap horror movie! Do yourself and your co-workers a huge favour, don't do this in regex!
|
|
-
10-10-2008, 5:32 AM |
-
prometheuzz
-
-
-
Joined on 04-28-2008
-
-
Posts 659
-
-
|
Re: Need an expression to validate numeric digit is sequential and sort ascending(desc) ,such as 123456 , 456789 are valid .
ddrudik: prometheuzz: Ah, a "curiosity-cabinet-regex", I like those! ; ) Here's mine:
^( (0(?=1|$))?((?<=0|^)1(?=2|$))?((?<=1|^)2(?=3|$))?((?<=2|^)3(?=4|$))?((?<=3|^)4(?=5|$))?((?<=4|^)5(?=6|$))?((?<=5|^)6(?=7|$))?((?<=6|^)7(?=8|$))?((?<=7|^)8(?=9|$))?((?<=8|^)9)? | (9(?=8|$))?((?<=9|^)8(?=7|$))?((?<=8|^)7(?=6|$))?((?<=7|^)6(?=5|$))?((?<=6|^)5(?=4|$))?((?<=5|^)4(?=3|$))?((?<=4|^)3(?=2|$))?((?<=3|^)2(?=1|$))?((?<=2|^)1(?=0|$))?((?<=1|^)0)? )$
Not that it changes the pattern any, but here's that without the whitespace and extra capture groups: ^(?:(?:0(?=1|$))?(?:(?<=0|^)1(?=2|$))?(?:(?<=1|^)2(?=3|$))?(?:(?<=2|^)3(?=4|$))?(?:(?<=3|^)4(?=5|$))?(?:(?<=4|^)5(?=6|$))?(?:(?<=5|^)6(?=7|$))?(?:(?<=6|^)7(?=8|$))?(?:(?<=7|^)8(?=9|$))?(?:(?<=8|^)9)?|(?:9(?=8|$))?(?:(?<=9|^)8(?=7|$))?(?:(?<=8|^)7(?=6|$))?(?:(?<=7|^)6(?=5|$))?(?:(?<=6|^)5(?=4|$))?(?:(?<=5|^)4(?=3|$))?(?:(?<=4|^)3(?=2|$))?(?:(?<=3|^)2(?=1|$))?(?:(?<=2|^)1(?=0|$))?(?:(?<=1|^)0)?)$ prometheuzz, excellent pattern.
Thanks, ddrudik. ; ) I just realized there is no need to use look behinds. This will do as well: ^ ( ((1(?=2|$))?(2(?=3|$))?(3(?=4|$))?(4(?=5|$))?(5(?=6|$))?(6(?=7|$))?(7(?=8|$))?(8(?=9|$))?9?) | ((9(?=8|$))?(8(?=7|$))?(7(?=6|$))?(6(?=5|$))?(5(?=4|$))?(4(?=3|$))?(3(?=2|$))?(2(?=1|$))?1?) ) $
|
|
-
10-15-2008, 5:11 AM |
-
sparky
-
-
-
Joined on 10-07-2008
-
-
Posts 18
-
-
|
Re: Need an expression to validate ABCABDABE , (A B C D E are numeric digit , C D E must be serial and sort ascending) , such as 134135136 is valid ...
Hi ,ddrudik , Thanks for your excellent effort in advance. ^0(\d\d)(?:0\1[1]\1[2]|1\1[2]\1[3]|2\1[3]\1[4]|3\1[4]\1[5]|4\1[5]\1 |5\1 \1[7]|6\1[7]\1 |7\1 \1[9])$ can validate ABCABDABE effectively , but how can you validate ABCADCAEC , (A B C D E are numeric digit , B D E must be serial and sort ascending) , such as 138148158 is valid ... I write a case like you do as above,but doesn't work , regular expression as follow , please help me ... ^0(\d)(?: 0(\d)\1[1]\2\1[2]\2| 1(\d)\1[2]\2\1[3]\2| 2(\d)\1[3]\2\1[4]\2| 3(\d)\1[4]\2\1[5]\2| 4(\d)\1[5]\2\1 \2| 5(\d)\1 \2\1[7]\2| 6(\d)\1[7]\2\1 \2| 7(\d)\1 \2\1[9]\2| )$ Thanks & Best regards, Sparky
|
|
-
10-15-2008, 5:13 AM |
-
sparky
-
-
-
Joined on 10-07-2008
-
-
Posts 18
-
-
|
Re: Need an expression to validate ABCABDABE , (A B C D E are numeric digit , C D E must be serial and sort ascending) , such as 134135136 is valid ...
Hi ,ddrudik , Thanks for your excellent effort in advance. ^0(\d\d)(?:0\1[1]\1[2]|1\1[2]\1[3]|2\1[3]\1[4]|3\1[4]\1[5]|4\1[5]\1 |5\1 \1[7]|6\1[7]\1 |7\1 \1[9])$ can validate ABCABDABE effectively , but how can you validate ABCADCAEC , (A B C D E are numeric digit , B D E must be serial and sort ascending) , such as 138148158 is valid ... I write a case like you do as above,but doesn't work , regular expression as follow , please help me ... ^0(\d)(?: 0(\d)\1[1]\2\1[2]\2| 1(\d)\1[2]\2\1[3]\2| 2(\d)\1[3]\2\1[4]\2| 3(\d)\1[4]\2\1[5]\2| 4(\d)\1[5]\2\1 \2| 5(\d)\1 \2\1[7]\2| 6(\d)\1[7]\2\1 \2| 7(\d)\1 \2\1[9]\2| )$ Thanks & Best regards, Sparky
|
|
Page 2 of 2 (23 items)
2
|
|
|