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

RegEx Conditional Problem HELP!!!

Last post 11-02-2009, 2:27 PM by Bree. 2 replies.
Sort Posts: Previous Next
  •  11-02-2009, 10:28 AM 57094

    RegEx Conditional Problem HELP!!!

    Hi everyone.  My name is Bree and I am TERRIBLE at Regular Expressions.  I have a problem that I am not sure how to solve so I came here.  I reviewed the Library and didn't find exactly what I needed and didn't know how to modify what I did find to work.  So you all are experts let me tell you what I want to do and maybe you can steer me in the right direction.

    First off I know that I am trying to do something RegEx was NOT designed to do.  But we always push the envelope, don't we?? :-))

    I am reading a log file with Perl.  I am trying to find any pattern that matches the string D<space><6 character alpha string><space><up to 3 digits><dot><4 digits> where the D is present and the <up to 3 digits> is between say 3 and 120.  In some cases (new regex pattern) the 3 might be 4 or some other integer greater than 0.

    The conditional numeric comparison is of course the problem.  I think it can be done with the RegEx conditional operator ? which is recognized by Perl.  I saw some comparisons in the library but they always used 0 as the start.  That doesn't work for me.  I need various non-zero thresholds such as 3.  There may or may not be a digit in the hundreds or tens place or even in the single digit place.  But there will always be a decimal and trailing digits.  I don't really care about those.  I really only care about digits in front of the decimal.  

    Can you guys and gals help??   If so please post here or email me your idea at breeliz@verizon.net

    Thank you so much!!!
    Bree

     


    Thx!
    Bree
  •  11-02-2009, 11:31 AM 57096 in reply to 57094

    Re: RegEx Conditional Problem HELP!!!

    I can't say I clearly understand your question, but I am confused as to why you don't use your programming language to evaluate the digits of the match?  Regexes that match numeric range while can be done are not really the best application of them.  They are easy write incorrectly and are not easy to maintain.

    The following will match your described sample.  Assuming alphas are just the English alphabet.

    D\x20[A-Za-z]{6}\x20([0-9]{0,3})\.[0-9]{4}

    The integer value will be in group 1. You can convert that to a integer and perform your logic test.  If you don't understand grouping read the this http://regexadvice.com/blogs/mash/archive/2007/06/01/You_2700_ve-got-your-sub_2D00_matches-in-my-matches.aspx


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  11-02-2009, 2:27 PM 57103 in reply to 57096

    Re: RegEx Conditional Problem HELP!!!

    Good question... I can't invade the Perl code... it's canned.  But the Perl interpreter will parse the RegEx expression that I input into the log file reader's config file.

    Sorry I should have made that a bit more clear.

    Bree


    Thx!
    Bree
View as RSS news feed in XML