regex - Perl, regular expression, matching exactly 2 spaces does not work -


working on parser sta/ssta timing reports. following cases of "arrival time" occurrence possible:

  arrival time                3373.000 - arrival time                          638.700 | 100.404                              arrival time report                            

the goal match cases 1st , 2nd, ignore 3rd case.

i tried 2 matching patterns in perl code:

1) if (m/^-?\s{1,2}arrival\stime/) { ($sta_data{$file}{$path}{arrival_time}) = m/\sarrival\stime\s+(.*)\s+$/ }

2) if (m/^-\sarrival\stime/ || m/^\s{1,2}arrival\stime/) { ($sta_data{$file}{$path}{arrival_time}) = m/\sarrival\stime\s+(.*)\s+$/ }

both of them pick 3rd case well. not understand why. defined 1 or 2 space characters \s{1,2}, no more that. 3rd line contains more 2 whitespace character should not match pattern. how possible?

the data have published not same used in test.

this program checks both of regex patterns against data copied directly edit of original post. neither pattern matches of lines in data

use strict; use warnings; use 5.010;  (%sta_data, $file, $path);  while ( <data> ) {      if ( /^-?\s{1,2}arrival\stime/ )  {         'match1';         $sta_data{$file}{$path}{arrival_time} = m/\sarrival\stime\s+(.*)\s+$/     }      if ( /^-\sarrival\stime/ or m/^\s{1,2}arrival\stime/ ) {         'match2';         $sta_data{$file}{$path}{arrival_time} = m/\sarrival\stime\s+(.*)\s+$/     } }  __data__       arrival time                3373.000     - arrival time                          638.700 | 100.404                                  arrival time report                            

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -