Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > regex_replace()

Reply
Thread Tools

regex_replace()

 
 
Friedel Jantzen
Guest
Posts: n/a
 
      05-10-2011
Hi!
Using MSVS 2008, STL TR1 <regex>.

Is there a way to get to know the number of replacements done by
regex_replace(), or at least, whether there was a replacement at all?
Ok, I can compare if(output != input) after regex_replace(), but this is
wasted performance, if there is a better way.

If a regex_error is thrown, how can I get the position of the error in the
regular expression string?

I found that icase (ignore case) only works with A-Za-z, but e.g. not with
German Umlaute (Ää etc.), though I set my German user locale using
regex::imbue(). Am I missing something?

TIA,
Friedel
 
Reply With Quote
 
 
 
 
Michael Doubez
Guest
Posts: n/a
 
      05-10-2011
On 10 mai, 09:23, Friedel Jantzen <nospam_...@freenet.de> wrote:
> Hi!
> Using MSVS 2008, STL TR1 <regex>.
>
> Is there a way to get to know the number of replacements done by
> regex_replace(), or at least, whether there was a replacement at all?
> Ok, I can compare if(output != input) after regex_replace(), but this is
> wasted performance, if there is a better way.


You can roll your own: regex_replace basically instantiate a
regex_iterator from the parameters an performs the replace. It
shouldn't be too hard.

> If a regex_error is thrown, how can I get the position of the error in the
> regular expression string?


AFAIS you cannot; and POSIX regcomp doesn't give more information
either.
You will need a regex format validator.

> I found that icase (ignore case) only works with A-Za-z, but e.g. not with
> German Umlaute (Ää etc.), though I set my German user locale using
> regex::imbue(). Am I missing something?


This may not be implemented or handled correctly by the compiler.

--
Michael
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      05-10-2011
Michael Doubez <> wrote:
> You will need a regex format validator.


You can use a regexp to validate a regexp string. There would be a
marvelous conceptual recursion there...

 
Reply With Quote
 
Michael Doubez
Guest
Posts: n/a
 
      05-10-2011
On 10 mai, 16:47, Juha Nieminen <nos...@thanks.invalid> wrote:
> Michael Doubez <michael.dou...@free.fr> wrote:
> > You will need a regex format validator.

>
> * You can use a regexp to validate a regexp string. There would be a
> marvelous conceptual recursion there...


I hesitated to make the joke but IMO regex grammar is not powerful
enough to validate regex expression.

I actually tried to find one available on the net in C or C++ but,
strangely, none seem readily available (I didn't look too hard, just
googled a bit).

--
Michael
 
Reply With Quote
 
Alain Ketterlin
Guest
Posts: n/a
 
      05-10-2011
Michael Doubez <> writes:

> On 10 mai, 16:47, Juha Nieminen <nos...@thanks.invalid> wrote:
>> Michael Doubez <michael.dou...@free.fr> wrote:
>> > You will need a regex format validator.

>>
>> Â* You can use a regexp to validate a regexp string. There would be a
>> marvelous conceptual recursion there...

>
> I hesitated to make the joke but IMO regex grammar is not powerful
> enough to validate regex expression.


You're right, regular expression languages are not regular.

-- Alain.
 
Reply With Quote
 
Friedel Jantzen
Guest
Posts: n/a
 
      05-11-2011
> You can use a regexp to validate a regexp string. There would be a
> marvelous conceptual recursion there...



A homespun validator could possibly not return the same position where the
engine has detected the error.

Friedel
 
Reply With Quote
 
Friedel Jantzen
Guest
Posts: n/a
 
      05-11-2011
Thank you for your reply!
....
> You can roll your own: regex_replace basically instantiate a
> regex_iterator from the parameters an performs the replace. It
> shouldn't be too hard.


I wrote test code to do this, but as STL regex is new for me, I thought I
could have missed something and reinvent the wheel.
....
> AFAIS you cannot; and POSIX regcomp doesn't give more information
> either.
> You will need a regex format validator.




>> I found that icase (ignore case) only works with A-Za-z, but e.g. not with
>> German Umlaute (Ää etc.), though I set my German user locale using
>> regex::imbue(). Am I missing something?

>
> This may not be implemented or handled correctly by the compiler.


Yes, it looks somehow "premature" to me.

Thank you,
Friedel
 
Reply With Quote
 
Michael Doubez
Guest
Posts: n/a
 
      05-11-2011
On 11 mai, 08:02, Friedel Jantzen <nospam_...@freenet.de> wrote:
> >> I found that icase (ignore case) only works with A-Za-z, but e.g. not with
> >> German Umlaute (Ää etc.), though I set my German user locale using
> >> regex::imbue(). Am I missing something?

>
> > This may not be implemented or handled correctly by the compiler.

>
> Yes, it looks somehow "premature" to me.


You could try toupper/tolower with your local and see if works on the
umlaut (and the eszett ).

--
Michael
 
Reply With Quote
 
Ralf Goertz
Guest
Posts: n/a
 
      05-11-2011
Michael Doubez wrote:


> You could try toupper/tolower with your local and see if works on the
> umlaut (and the eszett ).


I was about to tell you that there is no uppercase "ß". But then I
noticed the smiley which made me think that you knew. So I will refrain
from telling you.
 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      05-11-2011
Juha Nieminen <> writes:

> Michael Doubez <> wrote:
>> You will need a regex format validator.

>
> You can use a regexp to validate a regexp string. There would be a
> marvelous conceptual recursion there...


Nope, at least not by itself. The language of regexps not itself regular.
I don't know the exact details of TR1 regexps, but I doubt they can
check for matched parentheses.

/L
--
Lasse Reichstein Holst Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments