R
Ramon F Herrera
Hello all,
My initial task was to match the well-known notation used in math and
other fields to denote integer sequences. Such notation is nice,
unambiguous and -some times- succinct:
1,2,3,4,8-10,11-14
which is equivalent to:
1-4,8-14
(and to may other possibilities, the one immediately above being the
most succinct possible)
I have been able to come up with a regular expression which
unequivocally matches any valid "statement" of such "language". See
below.
My problem is that now I would like to write a more general form of
such sequence matching. The "base unit" is not an integer anymore. I
will post the actual question next.
-Ramon
ps: You will notice that this is not written in Perl, but in C++ and
will be used in some sort of "Perl emulator" (actually a Regex package
for C++). For obvious reason, a Perl NG is the best place to find the
appropriate experts. I am sure some of you can devise regexes in your
sleep.
---------------------------
const char hyphen = '-';
const char left_paren = '(';
const char right_paren = ')';
const char bar = '|';
const char comma = ',';
const char star = '*';
const string number = "[0-9]+";
const string range = number + hyphen + number;
const string term = left_paren + number + bar + range +
right_paren;
const string sequence = term + bar + left_paren + term + comma +
right_paren + star + term;
My initial task was to match the well-known notation used in math and
other fields to denote integer sequences. Such notation is nice,
unambiguous and -some times- succinct:
1,2,3,4,8-10,11-14
which is equivalent to:
1-4,8-14
(and to may other possibilities, the one immediately above being the
most succinct possible)
I have been able to come up with a regular expression which
unequivocally matches any valid "statement" of such "language". See
below.
My problem is that now I would like to write a more general form of
such sequence matching. The "base unit" is not an integer anymore. I
will post the actual question next.
-Ramon
ps: You will notice that this is not written in Perl, but in C++ and
will be used in some sort of "Perl emulator" (actually a Regex package
for C++). For obvious reason, a Perl NG is the best place to find the
appropriate experts. I am sure some of you can devise regexes in your
sleep.
---------------------------
const char hyphen = '-';
const char left_paren = '(';
const char right_paren = ')';
const char bar = '|';
const char comma = ',';
const char star = '*';
const string number = "[0-9]+";
const string range = number + hyphen + number;
const string term = left_paren + number + bar + range +
right_paren;
const string sequence = term + bar + left_paren + term + comma +
right_paren + star + term;