Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-07-23 22:43:52


Hello all,
        I've been toying around with an alternate, more concise syntax for common
regular expression operations. Perl is a personal favorite for string
manipulation, so I've partially mimicked its syntax as an add-on module to
regex. I rarely find that I require more than these simple operations (match
and sed-like replace).
        
------- Sample uses ----------
std::string s = "foobar";
boost::regex re("o*b");

if (s / re) { ... } // does re match any part of s?

boost::matches<std::string> m = s/re;
if (m) { // found a match
  std::cout << m.prematch() << std::endl; // before matched substring
  std::cout << m.match() << std::endl; // matched substring
  std::cout << m.postmatch() << std::endl; // after matched substring
};

// replace all instances of any number of "o"'s followed by a "b" with
// a "z", and return the resulting string.
std::string result = s / re / "z";
------------------------------

        I'm open to additional/alternate syntax, though I do believe some form of
shorthand is necessary. There is, to some extent, prior art for this syntax
within sed and perl. The code is available at:

http://groups.yahoo.com/group/boost/files/perlish-20010723.tgz

        Comments appreciated, as always.
        Doug


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk