in reply to perl regexp question excluding strings
With regular expressions you can often choose the easy way or the hard way. Although it's tempting to try and solve the whole problem with a single regular expression, that is often the hard way and the easy way is to take a step back and use multiple simple expressions instead. Consider:
use strict; use warnings; my @strings = split "\n", <<STRS; Context Servername Servername Context Servername DBServer Context Servername BogusServer STRS for my $str (@strings) { next if $str =~ /Context\s+Servername|Servername\s+Context/; next if $str !~ /Servername\s+(\w+)/; print "Matched: $1\n"; }
Prints:
Matched: DBServer
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl regexp question excluding strings
by bobg2011 (Novice) on Nov 05, 2011 at 02:01 UTC |