C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

why regex "^$" or "^s*$" cannot match "" line?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
bingfeng
Guest





PostPosted: Wed Jul 27, 2005 3:34 pm    Post subject: why regex "^$" or "^s*$" cannot match "" line? Reply with quote



{Moderator's note: although I think that Boost specific questions are
off-topic in comp.lang.c++.moderated, I let this article pass because
TR1 includes regular expressions which are pretty close, if not identical,
to Boost::Regex. -mod/dk}

I use boost:regex in my project. I find regex "^$" or "^s*$" cannot
match "" line, but perl do. the match_flag_type is match_default and
some other reg express can do.

Can someone give me some hints? thks


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Pete Becker
Guest





PostPosted: Wed Jul 27, 2005 5:37 pm    Post subject: Re: why regex "^$" or "^s*$" cannot match "" line? Reply with quote



bingfeng wrote:
Quote:
{Moderator's note: although I think that Boost specific questions are
off-topic in comp.lang.c++.moderated, I let this article pass because
TR1 includes regular expressions which are pretty close, if not identical,
to Boost::Regex. -mod/dk}

I use boost:regex in my project. I find regex "^$" or "^s*$" cannot
match "" line, but perl do. the match_flag_type is match_default and
some other reg express can do.

Can someone give me some hints? thks


Sounds like a bug in the boost version. In our not-yet-available
implementation of TR1 both of those searches succeed.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Thomas Maeder
Guest





PostPosted: Wed Jul 27, 2005 6:40 pm    Post subject: Re: why regex "^$" or "^s*$" cannot match "" line? Reply with quote



"bingfeng" <bfzhao (AT) gmail (DOT) com> writes:

Quote:
I use boost:regex in my project. I find regex "^$" or "^s*$" cannot
match "" line, but perl do. the match_flag_type is match_default and
some other reg express can do.

Can someone give me some hints? thks

The second expression looks wrong. Did you mean to write "^\s*$"?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
bingfeng
Guest





PostPosted: Thu Jul 28, 2005 11:50 am    Post subject: Re: why regex "^$" or "^s*$" cannot match "" line? Reply with quote

Yeah, It's "^\s*$"! I allow user enter a regex, than I match all text.
I use the one user entered.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Thu Jul 28, 2005 12:32 pm    Post subject: Re: why regex "^$" or "^s*$" cannot match "" line? Reply with quote

bingfeng wrote:
Quote:
I use boost:regex in my project. I find regex "^$" or "^s*$" cannot
match "" line, but perl do. the match_flag_type is match_default and
some other reg express can do.

Can someone give me some hints? thks

Where do you get the line from? If the 'n' is still there,
then "^$" shouldn't match, and of course, in "^s*$", there's
undefined behavior, because you have an undefined escape
sequence in the string -- you probably want "^\s*$", so that
the regex parser sees the ''.

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Pete Becker
Guest





PostPosted: Thu Jul 28, 2005 3:07 pm    Post subject: Re: why regex "^$" or "^s*$" cannot match "" line? Reply with quote

[email]kanze (AT) gabi-soft (DOT) fr[/email] wrote:
Quote:

Where do you get the line from? If the 'n' is still there,
then "^$" shouldn't match,

His line was "", which should match "^$". In addition, by default the
various regex matching functions treat their input sequence as a
complete line. So "n" won't exactly match "^$", i.e. regex_match will
return false, but its head matches the pattern, so regex_search will
succeed, and find the "first" line, consisting of just the newline
character. At least, that's my interpretation of the ECMAScript rules,
and it's what our implementation does.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.