Presumably it's because you're not anchoring the regexp to the start of the string - you're original regexp will work with 2 #s because it finds a match starting at the 2nd one. If you were to start your regexp thus: "^[#]P" then it would not say that the ## case was correct. -----Message d'origine----- De : boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] De la part de llwaeva@21cn.com Envoyé : 16 March 2007 07:45 À : boost-users@lists.boost.org Objet : [Boost-users] why the following regexp doesn't meet my requirement? Hi there, First of all, sorry for so many questions on using of regex. Actually, I am a beginner of regular expression; it is hard for me to understand some terms in document. I am going to extract a string in some pattern like #P{EXP_BEING_EXTRACTED} here, EXP_BEING_EXTRACTED is any expression which I want. For instance, xyz in #P{xyz} and 123_456 in #P{123_456}. But, I also need to ignore the case with double # as prefix, i.e. the output of ##P{123} should be kept unchanged. I use regex_search string source; // source contains the text being handled #P{x} or ##P{x} may occur boost::regex regexp; string::const_iterator start, end; boost::match_resultsstd::string::const_iterator what; boost::match_flag_type flags = boost::match_default; regexp = "[#]\{1\}P[{]\([^}]*\)[}]"; start = source.begin(); end = source.end(); if ( regex_search(start, end, what, regexp, flags) ) { // get the expression inside {} here // 1) get the text: string( what[1].first, what[1].second) // 2) replace the whole matched string, i.e., replace string(what[0].first, what[1].second); } The code above is fine for #P{x}; however, for the case ##P{x} regex_search still returns true. It seems that the regex_search firstly found the ##P{x} which is not match the regular expression; then, it go ahead from the second # and do the match again, so it found #P{x} finally. I don't know if the process is similiar to what I depict. Anyway, I just want to know how can I ignore the case ##P{x}. I try to modify the regular expression as follow regexp = "[^#]#P[{]\([^}]*\)[}]"; But, as I mentioned above, the whole matached string, namely #P{x}, will be replaced once the match is found. So, the character [^#] will also be replaced, that is not what I want. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users