regex multiline help

  • Thread starter Lance Hoffmeyer
  • Start date
L

Lance Hoffmeyer

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top