$line =~ /pattern\s*=*\s*([\w\d\s\\\/\.\-\@\!\$\%\^\&\*\:\;\,\<\>]+)/
I know that this is NOT the way to go about it. I have tried to get everything but after the comment like this.
but it is not working.$line =~ /pattern\s*=*\s*(.+?)\s+[^#]/
QUESTION. What is the proper regex to do this?
use strict; use warnings; my $count; my $env = []; foreach my $line ( <DATA> ) { chomp($line); next if $line =~ /^\s*\#/; next if $line =~ /^$/; # file is in the format of # [zipcode] # regex (?<Zip>\d{5})-(?<Sub>\d{4}) # pattern 95076-1234 # pattern 90210-6473 # [IP] # regex = (?<First>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Second>2[0 +-4]\d|25[0-5]|[01]?\d\d?)\.(?<Third>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?< +Fourth>2[0-4]\d|25[0-5]|[01]?\d\d?) # pattern = 255.257.0.0 # invalid # # if ($line =~ /^\[([\w\s\\]+)\]/ ) { my $tag = $1; $count = scalar @{$env}; $env->[$count]->{tag} = $tag; } elsif ( $line =~ /regex\s*=*\s*(.+)|regex\s*=*\s*/ ) { my $regex = $1; if ( $env->[$count]->{'regex'} ) { $env->[$count]->{'regex'} .= $regex; }else{ $env->[$count]->{'regex'} = $regex; } } # comments are ignored elsif ( $line =~ /pattern\s*=*\s*([\w\d\s\\\/\.\-\@\!\$\%\^\&\ +*\:\;\,\<\>]+)|pattern\s*=*\s*/ ){ my $pattern = $1; push( @{$env->[$count]->{pattern}} , $pattern); } } __DATA__ [IP] regex = (?<First>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Second>2[0-4]\d|25[0 +-5]|[01]?\d\d?)\.(?<Third>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Fourth>2[0 +-4]\d|25[0-5]|[01]?\d\d?) pattern = 255.257.0.0 # invalid pattern = 192.168.1.1
In reply to Regex to ignore comment by crusty_collins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |