in reply to Re: What's wrong with this regex
in thread What's wrong with this regex

Thanks for the quick answer guys.

Unfortunately four groups is not going to help, it should match anthing from 1.2 to 1.2.3.4.5.6 etc, or anything follows this structure.

To look for a substring matching  [\d+\.]+ is also not an option, as there may be other matches in the string, like a simple number.

Replies are listed 'Best First'.
Re^3: What's wrong with this regex
by toolic (Bishop) on Mar 01, 2012 at 15:39 UTC
Re^3: What's wrong with this regex
by moritz (Cardinal) on Mar 01, 2012 at 15:54 UTC

    Sorry, I don't understand your answer. What exactly is wrong with the approach that uses split?

    $_ = '1.2.3.4.5.6 foo bar'; if (/((?:\d+\.)+(\d+)/) { my @matches = (split(/\./, $1), $2) }
Re^3: What's wrong with this regex
by Riales (Hermit) on Mar 01, 2012 at 15:46 UTC
    I'm thinking you don't need a beefy regex if that's all you want to do. How about something like this instead:
    my $string = '12.34.56.78 asdfasdfasdfasdfasdf'; my $numbers = shift @{[split ' ', $string]}; my @numbers = split '\.', $numbers; use Data::Dumper; print Dumper(@numbers) if $numbers =~ /^[\d.]+$/;

    EDIT: Whoops, sorry moritz - I confess to only skimming your answer and didn't notice that you had already suggested using split. Apologies!