
Would anyone be interested in having a perl-like regex shortcut notation? The original idea was born during a local C++ focus group discussion. Looking further into the feasibility I thought that this might be a useful addition to Boost. Possibly something like the following (from some proof-of-concept code) using namespace boost::short_regex; std::string str("And he said: 'BLAH BLAH'"); // [1] Substitutes first occurrence and copy (calls boost::regex_replace) // perl: ($s2=$str) =~ s/(BLAH)/Hooray/; std::string s2= _s / "(BLAH)" / "Hooray" / str; // [2] Substitute globally and copy // perl: ($s2=$str) =~ s/(BLAH)/Hooray/g; s2= _s / "(BLAH)" / "Hooray" / _g / str; // [3] Substitute first occurrence in-place // perl: $str=~ s/(BLAH)/Hooray/; ~_s/ "(BLAH)" / "Hooray" / str; In the above _s and _g are special placeholder/tag objects sort of like _1,_2. Other could include _i (case-insensitive), _m (string as multiple lines) and _s (string as single line). Multiple modifiers can be added using (,) // [4] Substitute globally and copy // perl: ($s2=$str) =~ s/(BLAH)/Hooray/gi; s2= _s / "(BLAH)" / "Hooray" / (_g,_i) / str; The purpose will not be to shortcut all of the boost.regex functionality, just the common cases, as in perl or sed. Cases [1] and [3] is very close to the perl and would be easy to understand, however [2] and [4] is moving away from perl-syntax. This might be considered illegible by some.

<Schalk_Cronje@McAfee.com> wrote in message:
Would anyone be interested in having a perl-like regex shortcut notation? The original idea was born during a local C++ focus group discussion.
What is a C++ focus group? A collection of randomly selected people who give their opinions on proposed changes to C++? <snip>
// [1] Substitutes first occurrence and copy (calls boost::regex_replace) // perl: ($s2=$str) =~ s/(BLAH)/Hooray/; std::string s2= _s / "(BLAH)" / "Hooray" / str;
Something like this would fit in easily with Eric Niebler's xpressive library. In fact, I suggested it, but Eric said it was "too cute". Perhaps we should convene a focus group to discuss the subject. ;-) Jonathan

On 2004-10-21, Jonathan Turkanis <technews@kangaroologic.com> wrote:
Would anyone be interested in having a perl-like regex shortcut notation? The original idea was born during a local C++ focus group discussion. What is a C++ focus group? A collection of randomly selected people who give
<Schalk_Cronje@McAfee.com> wrote in message: their opinions on proposed changes to C++?
That sounds like a standards committee, to me ;-)
std::string s2= _s / "(BLAH)" / "Hooray" / str; Something like this would fit in easily with Eric Niebler's xpressive library. In fact, I suggested it, but Eric said it was "too cute". Perhaps we should convene a focus group to discuss the subject. ;-)
Well, I thought it was cute too. It is certainly a more friendly C++ interface to those who come from regular expressions from more "traditional" (Unix) regexp backgrounds (sed, perl, etc). I'd put it on a par with iomanip. Yes, there are other ways of doing the same thing, but it's just not as nice to look at. Maybe that's just me... phil -- change name before "@" to "phil" for email

| -----Original Message----- | From: boost-bounces@lists.boost.org | [mailto:boost-bounces@lists.boost.org] On Behalf Of Phil Richards | Sent: 22 October 2004 09:26 | To: boost@lists.boost.org | Subject: Re: [boost] Re: Shortcut regex notation | | Well, I thought it was cute too. It is certainly a more friendly | C++ interface to those who come from regular expressions from more | "traditional" (Unix) regexp backgrounds (sed, perl, etc). But (perhaps sadly) to the majority, it is complete goobledegook! Same applies to the printf family, Fortran Hollerith codes ... Paul Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB +44 1539 561830 +44 7714 330204 mailto: pbristow@hetp.u-net.com

But (perhaps sadly) to the majority, it is complete goobledegook! Hrm.. maybe put _s etc. into a subnamespaces which has to be using'ed explicitely before being able to use the magic syntax directly?
Same applies to the printf family, Fortran Hollerith codes ... Of course I do realize it's a lot about the question whether boost wants to support such syntax at all. Considering that there is boost::format() which supports a printf()-esque style, it is definitely worth consideration, at least.
Cheers, Michael

Jonathan Turkanis wrote:
<Schalk_Cronje@McAfee.com> wrote in message:
Would anyone be interested in having a perl-like regex shortcut notation?
<snip>
// [1] Substitutes first occurrence and copy (calls boost::regex_replace) // perl: ($s2=$str) =~ s/(BLAH)/Hooray/; std::string s2= _s / "(BLAH)" / "Hooray" / str;
Something like this would fit in easily with Eric Niebler's xpressive library. In fact, I suggested it, but Eric said it was "too cute". Perhaps we should convene a focus group to discuss the subject. ;-)
In fact, you could use almost completely emulate perl syntax if you want to: string str = ...; sregex rex = ...; str ^= _s/rex/"c++ sux, perl rulz!!"/_g; It's certainly cute, and it would be an interesting exersice. It is also not particularly appealing to me, since the only reason I wrote a C++ regex engine in the first place was because I strongly disliked perl's syntax. And to me, it seems less like a domain-specific embeded language than like simply trying to write perl in C++ -- an endeavor of dubious value. There are many things I need to add to xpressive. This is far, far down the list, but if someone wanted to submit a patch to xpressive (including docs and tests!), I wouldn't be opposed to adding it (so long as it could be cleanly isolated in a nested namespace). -- Eric Niebler Boost Consulting www.boost-consulting.com

"Eric Niebler" <eric@boost-consulting.com> wrote in message news:41798CEF.4040807@boost-consulting.com...
Jonathan Turkanis wrote:
<Schalk_Cronje@McAfee.com> wrote in message:
Would anyone be interested in having a perl-like regex shortcut notation?
<snip>
// [1] Substitutes first occurrence and copy (calls boost::regex_replace) // perl: ($s2=$str) =~ s/(BLAH)/Hooray/; std::string s2= _s / "(BLAH)" / "Hooray" / str;
Something like this would fit in easily with Eric Niebler's xpressive library. In fact, I suggested it, but Eric said it was "too cute". Perhaps we should convene a focus group to discuss the subject. ;-)
It looks like the focus group is now in session ;-)
In fact, you could use almost completely emulate perl syntax if you want to:
string str = ...; sregex rex = ...;
str ^= _s/rex/"c++ sux, perl rulz!!"/_g;
This is closer to what I had in mind originally. Unfortunately (or fortunately, if you want to poke holes in the idea), you don't get the closing slash unles flags are provided. (Flag _e would be particularly interesting.)
It's certainly cute, and it would be an interesting exersice. It is also not particularly appealing to me, since the only reason I wrote a C++ regex engine in the first place was because I strongly disliked perl's syntax. And to me, it seems less like a domain-specific embeded language than like simply trying to write perl in C++
So you won't be contributing to the Boost.Perl library which I'm planning to write as soon as ISO Perl is complete? ;-)
-- an endeavor of dubious value.
I basically agree with your analysis, which is why I didn't press the issue. Jonathan

On Oct 20, 2004, at 4:49 AM, Schalk_Cronje@McAfee.com wrote:
Would anyone be interested in having a perl-like regex shortcut notation? The original idea was born during a local C++ focus group discussion. Looking further into the feasibility I thought that this might be a useful addition to Boost.
I had brought something like this up a few years ago: http://article.gmane.org/gmane.comp.lib.boost.devel/52511 It got a little bit of interest, but no overwhelming support. Doug
participants (7)
-
Doug Gregor
-
Eric Niebler
-
Jonathan Turkanis
-
Michael Walter
-
Paul A Bristow
-
Phil Richards
-
Schalk_Cronje@McAfee.com