in reply to Regex negative number question

Try:
$line=~/- # negative (?: # followed by \d+(?:\.\d+)? # digits possible followed by '.' digits | # or \.\d+ # '.' digits )/x; # with out comments looks like this $line=~/-(?:\d+(?:\.\d+)|\.\d+)/

Replies are listed 'Best First'.
Re: Re: Regex negative number question
by Not_a_Number (Prior) on Oct 06, 2003 at 20:02 UTC

    But then that rules out '-7.', which the OP explicitly wants to include.

    You could try this (leaving out the non-capturing ?:s for clarity):

    print "match" if $str =~ /-\d*((?<=\d)\.)|(\.(?=\d))/;

    but then that would match if:

    my $str = 'See answers on pages 234-235.'

    oh well...

    dave