in reply to Match zero times in regex
It does match zero times. In your code, (?:host){0} is matching "host" zero times starting at position 14.
1 2 3 4 012345678901234567890123456789012345678901234567 permit ip host 10.11.1.1 192.168.100.0 0.0.0.255
What about
if ( my ($pairs) = $entry =~ /^ \s* permit \s+ ip \s+ (?: host \s+ \S+ \s+ )? (.*)/x ) { while ( $pairs =~ /(\S+) \s+ (\S+)/xg ) { my ($ip, $mask) = ($1, $2); ... $ip ... $mask ... } }
Update: Fixed problem with solution.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Match zero times in regex
by Anonymous Monk on Dec 13, 2011 at 09:21 UTC | |
by ikegami (Patriarch) on Dec 13, 2011 at 20:00 UTC | |
|
Re^2: Match zero times in regex
by SomeNetworkGuy (Sexton) on Dec 13, 2011 at 03:39 UTC |