in reply to Using Regexp::Common

From Regexp::Common, that should work. Have you looked at the string that your call to RE_num_real returns? What does that string look like?

my $is_binary = RE_num_real(-keep, -group=>3, -sep=>',', -base=>2); print "Checking '$_' against /$is_binary/\n"; if( $_ =~ /$is_binary/ ) { print q{matched a number}; print "Got [$1]\n"; };

Replies are listed 'Best First'.
Re^2: Using Regexp::Common
by justrajdeep (Novice) on Sep 18, 2015 at 15:59 UTC

    Hi

    I just checked it out and i have no clue what that regular expression means :(

    this is what i see

    '(?^:((?i)([+-]?)((?=[.]?[0123456789])([0123456789]*)(?:([.])([0123456 +789]{0,}))?)(?:([E])(([+-]?)([0123456789]+))|)))

      An explanation (beware possible line wrap of intial print of long regex expression):

      c:\@Work\Perl\monks>perl -wMstrict -le "use Regexp::Common qw(RE_num_real); use YAPE::Regex::Explain; ;; print YAPE::Regex::Explain->new(RE_num_real(-keep, -group=>3, -sep=>' +,', -base=>2))->explain; " The regular expression: (?-imsx:((?i)([+-]?)((?=[.]?[0123456789])([0123456789]*)(?:([.])([0123 +456789]{0,}))?)(?:([E])(([+-])([0123456789]+))|))) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- (?i) set flags for this block (case- insensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally) ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- [+-]? any character of: '+', '-' (optional (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- ( group and capture to \3: ---------------------------------------------------------------------- (?= look ahead to see if there is: ---------------------------------------------------------------------- [.]? any character of: '.' (optional (matching the most amount possible)) ---------------------------------------------------------------------- [0123456789] any character of: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ---------------------------------------------------------------------- ) end of look-ahead ---------------------------------------------------------------------- ( group and capture to \4: ---------------------------------------------------------------------- [0123456789]* any character of: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \4 ---------------------------------------------------------------------- (?: group, but do not capture (optional (matching the most amount possible)): ---------------------------------------------------------------------- ( group and capture to \5: ---------------------------------------------------------------------- [.] any character of: '.' ---------------------------------------------------------------------- ) end of \5 ---------------------------------------------------------------------- ( group and capture to \6: ---------------------------------------------------------------------- [0123456789] any character of: '0', '1', '2', {0,} '3', '4', '5', '6', '7', '8', '9' (at least 0 times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \6 ---------------------------------------------------------------------- )? end of grouping ---------------------------------------------------------------------- ) end of \3 ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- ( group and capture to \7: ---------------------------------------------------------------------- [E] any character of: 'E' ---------------------------------------------------------------------- ) end of \7 ---------------------------------------------------------------------- ( group and capture to \8: ---------------------------------------------------------------------- ( group and capture to \9: ---------------------------------------------------------------------- [+-]? any character of: '+', '-' (optional (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \9 ---------------------------------------------------------------------- ( group and capture to \10: ---------------------------------------------------------------------- [0123456789] any character of: '0', '1', '2', + '3', '4', '5', '6', '7', '8', '9' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \10 ---------------------------------------------------------------------- ) end of \8 ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
      Please also see perlre, perlretut, and perlrequick. There are also a number of on-line regex explainers, but I'm not familiar enough with them to recommend any particular one. (Update: Actually, davido has a nice regex tester which ends up giving a fair amount of explanation, or at least enlightenment. See his personal node for a link)

      Update: Caution: YAPE::Regex::Explain only supports regex features added through Perl version 5.6.


      Give a man a fish:  <%-{-{-{-<

        WOW thats an amazing module !!!!

        I cannot thank you enough :)