regex multiline help

Discussion in 'Perl Misc' started by Lance Hoffmeyer, Feb 3, 2007.

  1. Hey all,

    I need a little help with a regex.

    Traditionally, I have found numbers in a particular column using the following regex (see table at bottom of page):

    $fileT1 =~ /TABLE\s+1.*?$BRAND2.*?(?:(\d{1,3}\.\d|\-)[A-T\s]+){2}/s;my $val = $1;if($1 eq "- "){$val=0} ###($1 = 0.6)

    but, the following is matching BRAND5, col 13 = 3.3, instead of BRAND4, col 13 = "-"
    $fileT1 =~ /TABLE\s+1.*?$BRAND4.*?(?:(\d{1,3}\.\d|\-)[A-T\s]+){13}/s;my $val = $1;if($1 eq "- "){$val=0}

    Basically, I want to find the line BRAND4, then ignore everything up until the next line, then I want to start the multimatch
    The "-" seem to be screwing my regex up:
    I tried using modifiers within the regex, but still not having any success.

    dot matches ^ and $, then after BRAND4, dot does not match ^ or $, rather I match it manually, allowing me to reach the newline
    of percentages.

    $fileT1 =~ /(?s)TABLE\s+1.*?BRAND4[$b](?m).*?^.*?(?:(\d{1,3}\.\d|\-)[A-T\s]+){$col}/;my $val = $1;if($1 eq "- "){$val=0}

    Any suggestions on how to modify my regex such that
    1) Find TABLE 1 then,
    2) Go past everything until BRAND 4 is found then
    3) match until the end of the line is reached (or there is a newline, or ^)
    4) then, start the multi-match

    Thanks in advance,

    Lance


    PAGE 1
    BANNER 13 COL
    TABLE 1
    XXXXXXXXX
    Q.1b



    COL 1 COL 2 COL 3 COL 4 COL 5 COL 6 COL 7 COL 8 COL 9 COL 10 COL 11 COL 12 COL 13
    ----- ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------
    (A) (B) (C) (D) (E) (F) (G) (H) (I) (J) (K) (L) (M)

    TOC
    BASE - TOTAL 1025 90* 111 103 138 64* 83* 53* 86* 88* 51* 77* 76*
    RESPONDENTS

    BRAND1 660 48 74 59 85 46 61 40 55 58 36 51 48
    64.4 53.5 66.8B 57.4 61.5 71.8BD 73.0BD 75.5BD 63.4 65.5 70.2B 65.5 63.0

    BRAND2 / TYPE 113 17 10 5 22 2 4 7 11 12 5 9 8
    (TEST) 11.0 19.1CDF 9.5 5.2 16.3DFG 2.5 4.5 13.7F 13.3DF 13.5DFG 9.1 11.4F 11.0
    G G

    BRAND3 43 2 8 12 4 1 3 1 1 2 6 3 2
    4.2 1.8 7.0 11.6BEF 2.7 0.8 3.1 2.0 1.2 1.8 11.4BEF 4.0 2.8
    GHIJM IJ

    BRAND4 13 1 - 5 1 1 1 1 1 - - 3 -
    1.2 0.6 - 5.1CEJ 0.8 1.7 0.6 1.0 0.6 - - 4.0 -

    BRAND5 7 2 1 1 - 1 1 - 1 - - - 3
    0.7 2.3 0.5 0.5 - 0.8 0.6 - 0.6 - - - 3.3
    Lance Hoffmeyer, Feb 3, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yatima

    Multiline regex help

    Yatima, Mar 3, 2005, in forum: Python
    Replies:
    13
    Views:
    547
    Kent Johnson
    Mar 4, 2005
  2. eggie5

    multiline regex expression

    eggie5, Jul 21, 2007, in forum: Java
    Replies:
    4
    Views:
    501
    Roedy Green
    Jul 22, 2007
  3. Gilles Ganault

    [2.5] Regex doesn't support MULTILINE?

    Gilles Ganault, Jul 22, 2007, in forum: Python
    Replies:
    9
    Views:
    299
    Gilles Ganault
    Jul 24, 2007
  4. Replies:
    3
    Views:
    716
    Reedick, Andrew
    Jul 1, 2008
  5. dale zhang
    Replies:
    8
    Views:
    396
    Tintin
    Nov 30, 2004
Loading...

Share This Page