in reply to Re: Print lines based on matching words
in thread Print lines based on matching words

From the script above -
my @keys = $line =~ /([A-Z\d]+[-_][A-Z\d]+)/ig;
Seems to match - WEB-CLIENT, SMTP_TCP etc.
But, how can I also match - MYCLIENTS-IP_1st, MYSRVR_IP-S_2nd etc.
__DATA__ access-list INSIDE_IN remark Web Users To Web Server access-list INSIDE_IN extended permit tcp object-group WEB-CLIENT obje +ct-group WEB-SERVER object-group WEB_TCP access-list INSIDE_IN remark EMAIL To EMAIL Server access-list INSIDE_IN extended permit tcp object-group EMAIL-CLIENT ob +ject-group EMAIL-SERVER object-group SMTP_TCP access-list INSIDE_IN remark SRVR to Client access-list INSIDE_IN extended permit tcp object-group MYSRVR_IP-S_2nd + object-group MYCLIENTS-IP_1st object-group WEB_TCP object-group network PC1_1st network-object host 10.1.1.11 object-group network PC2_1st network-object host 10.1.1.12 object-group network WEB-CLIENT group-object PC1_1st group-object PC2_1st object-group network WEB-SERVER network-object host 10.1.1.5 object-group service WEB_TCP tcp port-object eq www port-object eq https object-group network EMAIL-CLIENT group-object PC1_1st group-object PC2_1st object-group network EMAIL-SERVER network-object host 10.1.1.6 object-group service SMTP_TCP tcp port-object eq SMTP object-group network MYCLIENTS-IP_1st network-object host 10.1.2.1 network-object host 10.1.2.2 network-object host 10.1.2.3 network-object host 10.1.2.4 object-group network MYSRVR_IP-S_2nd network-object host 10.1.1.4 network-object host 10.1.1.3 network-object host 10.1.1.31 object-group service WEB_TCP tcp port-object eq www port-object eq https
Please let me know.

Replies are listed 'Best First'.
Re^3: Print lines based on matching words
by AnomalousMonk (Archbishop) on Dec 26, 2014 at 03:12 UTC

    Here's a way to match/extract ordinal substrings. Note this won't match an improper ordinal like '1th' or '4rd'. (Update: It's also case-sensitive.) Tested on Windows 7 under ActiveState 5.8.9 and Strawberry 5.14.4.

      Thank you for your reply. That's a nice way to match the rest.
      I however, using the following as it seems to fit my needs-
      while (defined(my $line = <$fh>)) { next if $line =~ /^access-list .*\bremark\b/; given ($line) { when (/^access-list/) { # take the next word followed by object-group /object-group\s/; my @after = split(/\s/,$'); my @keys = @after; push @lists, {groups => \@keys, line => $line}; } ............... } }