in reply to regular expression assistance

An interesting version is:

my $fail; if ($str =~ /\b(?>(\d{1,3})(??{$fail ||= $1 > 255})\.?){4}/ && ! $ +fail) { # matched ... }

Perl is environmentally friendly - it saves trees

Replies are listed 'Best First'.
Re^2: regular expression assistance
by chip (Curate) on May 10, 2008 at 00:43 UTC
    Sadly that pattern misinterprets 100100100100 as a valid IP.

    At the very least you'd want to replace \.? with (?:\.|\z) or the like.

        -- Chip Salzenberg, Free-Floating Agent of Chaos

      There are many ways of breaking the pattern. Most of them can't be resolved without knowing the nature of the strings being matched.

      The intent was to demonstrate a way of including the range test in the match rather than to strictly match IP number strings and nothing else. So don't be sad, learn from the technique and be happy. ;)


      Perl is environmentally friendly - it saves trees