in reply to What does this regex do?
You may find japhy's YAPE::Regex::Explain module to be useful in answering these types of question. You'll need to install YAPE::Regex first. This is waht it had to say about your example regex:
#!/usr/bin/perl -w use strict; use YAPE::Regex::Explain; my $exp = YAPE::Regex::Explain->new('^-?\.?\d+(?:\.\d+)?$'); print $exp->explain; The regular expression: (?-imsx:^-?\.?\d+(?:\.\d+)?$) 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): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- -? '-' (optional (matching the most amount possible)) ---------------------------------------------------------------------- \.? '.' (optional (matching the most amount possible)) ---------------------------------------------------------------------- \d+ digits (0-9) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- (?: group, but do not capture (optional (matching the most amount possible)): ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- \d+ digits (0-9) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- )? end of grouping ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
Which may or may not help :-). Note that it acts as if the regex you supply had (?-imsx: ... ) wrapped around it, which could be a bit confusing.
|
|---|