From -2982906483737299299
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ee5799d644d099ed,start
X-Google-Attributes: gidf78e5,public
From: mottl@miss.wu-wien.ac.at (Markus Mottl)
Subject: Regex-class that works with STL
Date: 1998/01/13
Message-ID: <69fnmm$ini@cantine.wu-wien.ac.at>#1/1
X-Deja-AN: 315647362
X-Original-Date: 13 Jan 1998 12:46:14 GMT
Originator: austern@isolde.mti.sgi.com
Organization: University of Economics and Business Administration, Vienna, Austria
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBNLvXPEy4NqrwXLNJAQHPWQIAulvY5dnfPq1acjTosmkfP8AvDftci2Je laH6OBdQmqC4Zd3/5Hq05hbZjKwj5qbwnXeJy3qOIEd7YzIIXPEYzg== =3WYC
Newsgroups: comp.std.c++


I would like to know, whether there is a free implementation of a
Regex-class for matching regular expressions in STL-objects of "string",
"istream",...

Why does such an important class for matching input or other data miss
in the STL?  Practically every program has to read in input and has to
make sure that it matches some sort of pattern. Adding a Regex-class
could greatly reduce line numbers as well as errors.


An interesting capability would also be to match "regular" sequences
of objects.

Example: You have the following vector of integers: 31 71 71 11 15 15 15 1
Now you want to take out every sequence of equal numbers (more than one)
(in this case 71 71 and 15 15 15 - leaving 31 11 1 in the container)

Maybe the solution could work like this:
(better strategies very welcome ;-) )

---
// vector<int> my_vector already contains the numbers above...
RegexContainer<int> my_regex_container;

my_regex_container.push_back(".{2,}"); // . -> always match
                                       // {2,} -> match at least two times

// This takes all elements described by the regular expression in
// "my_regex_container" out of "my_vector" (starting-point is the first
// element)
my_regex_container.take_out_from(&my_vector[0]);
---

The member-function "push_back" of "RegexContainer" might also take
as argument a value to match of type "int" (in the example) or even a
function-object which operates on an element and returns a bool, whether
the current element fulfils a certain condition (match attributes of an
object rather than the object itself).

I know that not everything can be placed into the STL. Still, I miss
general concepts like regular expressions. (You, too???)
This method of pattern specification is very much appreciated in many
areas, reaching from theoretical computer science over operating systems
(you can find it nearly everywhere in UNIX) and it is even integral part
of a whole programming language (PERL).

Regards,
Markus Mottl

--
*  Markus Mottl              |  University of Economics and       *
*  Department of Applied     |  Business Administration           *
*  Computer Science          |  Vienna, Austria                   *
*  mottl@miss.wu-wien.ac.at  |  http://miss.wu-wien.ac.at/~mottl  *
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



