Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Need an expression to validate a digit in a numeric string ,compare which is the bigger digit...

Last post 10-10-2008, 11:07 AM by mash. 6 replies.
Sort Posts: Previous Next
  •  10-09-2008, 4:06 AM 47037

    Need an expression to validate a digit in a numeric string ,compare which is the bigger digit...

    Example: 1245A78    how to compare with the fifth digit A  ?  if ( A > 5 ) , the expression is valid ...
  •  10-09-2008, 4:31 AM 47039 in reply to 47037

    Re: Need an expression to validate a digit in a numeric string ,compare which is the bigger digit...

    sparky:
    Example: 1245A78    how to compare with the fifth digit A  ?  if ( A > 5 ) , the expression is valid ...

    What do you mean? Is there an A in your string or some numerical value? Is the numerical value one digit or can it be multiple digits? A bit more detail, please.

    But you realize by now (after your previous post) that regexes are not the right tool for numerical comparison, right?

  •  10-09-2008, 10:44 AM 47050 in reply to 47037

    Re: Need an expression to validate a digit in a numeric string ,compare which is the bigger digit...

    sparky:
    Example: 1245A78    how to compare with the fifth digit A  ?  if ( A > 5 ) , the expression is valid ...

    First let me say when posting a question please follow the posting guidelines.  Do so with each post as you have no guarantee that to person who tries to help you will have read any previous post you made.

    Second this is not a regex task.  Regular Expressions do not perform any mathematical evaluations

    http://regexadvice.com/blogs/mash/archive/2007/06/01/Are-you-ready-for-regex_3F00_.aspx

    You task is a coding issue. You can use a regex as part of your code but the logic of your function must come from your code.


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  10-09-2008, 8:27 PM 47056 in reply to 47037

    Re: Need an expression to validate a digit in a numeric string ,compare which is the bigger digit...

    If you mean that you want to make sure that the first occurrence of the letter 'A' is in the 5th, 6th.....position within the string then

    [^A]{4}[^A]*A

    will do in regex what would be trivial in a programming language (if 5 <= indexof("A", text) then...). It works by requiring that the first 4 characters are not 'A', skipping any number (including 0) of non-'A's after that and matching on 'A' in the text. If there was an 'A' within the first 4 characters or there was not an 'A' in the 5th character position or beyond, then the match will fail.

    Of course the matching can start anywhere within the text so you probably should use

    ^[^A]{4}[^A]*A

    to force the match from the start of the text/line (depending on the 'multiline' option setting)

    Susan

    PS: Your question is a bit confusing in that the 'A' is in the 5th position of your sample text, but you (appear to) say that the expression is valid if 'A' it beyond the 5th position - therefore the sample text would return an 'invalid' status. Correct?

  •  10-10-2008, 5:09 AM 47066 in reply to 47037

    Re: Need an expression to validate a digit in a numeric string ,compare which is the bigger digit...

    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 . letter 'A'  just stand for a bit digit,it can be unbending and random ...

          So my question is how to compare with the digit which letter 'A' stand for . take an examle: 2954A121  ,if (A=6) the expression should be 29546121 , so if I want to take 'A' compare to a solid digit(e.g. 8) ,  if(A<8)  then the digit is valid , if not ,it's invalid .  actually 6<8

     Many thanks and best regards,

    Sparky

  •  10-10-2008, 5:40 AM 47069 in reply to 47066

    Re: Need an expression to validate a digit in a numeric string ,compare which is the bigger digit...

    sparky:

    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 . letter 'A'  just stand for a bit digit,it can be unbending and random ...

          So my question is how to compare with the digit which letter 'A' stand for . take an examle: 2954A121  ,if (A=6) the expression should be 29546121 , so if I want to take 'A' compare to a solid digit(e.g. 8) ,  if(A<8)  then the digit is valid , if not ,it's invalid .  actually 6<8

     Many thanks and best regards,

    Sparky

    Sparky, I get the impression you still didn't read the posting guide lines, please do so. By doing so, you are helping us help you.

    Second, you are using a lot of "home grown terminology": I don't know what you mean by "solid digit", "bit digit", "unbending".

  •  10-10-2008, 11:07 AM 47074 in reply to 47066

    Re: Need an expression to validate a digit in a numeric string ,compare which is the bigger digit...

    sparky:

    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 . letter 'A'  just stand for a bit digit,it can be unbending and random ...

          So my question is how to compare with the digit which letter 'A' stand for . take an examle: 2954A121  ,if (A=6) the expression should be 29546121 , so if I want to take 'A' compare to a solid digit(e.g. 8) ,  if(A<8)  then the digit is valid , if not ,it's invalid .  actually 6<8

     Many thanks and best regards,

    Sparky

    If I understand your question correctly that you want a regex to at some point compare one digit to another to evaluate which is mathematically greater or less than the other I  don't think you are clear on what regexes do.  So once again I will refer you to this article.  http://regexadvice.com/blogs/mash/archive/2007/06/01/Are-you-ready-for-regex_3F00_.aspx please do yourself a favor and read it.

    To be clear, regexes DO NOT perform mathematical evaluations. Logical comparisons such as greater than or less than have no meaning to a regular expression.  You the programmer would have to write code to perform such test.


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
View as RSS news feed in XML