Named subexpressions using \k<name>

I have a user who says they have a bunch of expressions written for the Oniguruma regex library that use \k<name> syntax. According to http://www.boost.org/doc/libs/1_44_0/libs/regex/doc/html/boost_regex/syntax/... Boost.regex should also support that syntax, but it does not seem to work. For example: boost::regex_replace( std::string("xyyz"), boost::regex(".*(?<first>x)(?<second>y).*", boost::regex_constants::perl), std::string("$+{second}\\k<first>"), boost::match_default | boost::format_all | boost::match_extra); results in "yk<first>" This result shows that $+{second} evaluated to "y" but \k<first> evaluated to "k<first>". I thought maybe the \k<name> syntax was only supported as a backreference within the first regex instead of the replace string, but this doesn't work either: boost::regex_replace( std::string("xyyz"), boost::regex(".*(?<first>x)(?<second>y)\\k<second>.*", boost::regex_constants::perl), std::string("$+{second}"), boost::match_default | boost::format_all | boost::match_extra); The result is "xyyz" meaning nothing was replaced (the regex did not match). However, if modify the regex to use \\g{name} syntax, it works: boost::regex_replace( std::string("xyyz"), boost::regex(".*(?<first>x)(?<second>y)\\g{second}.*", boost::regex_constants::perl), std::string("$+{second}"), boost::match_default | boost::format_all | boost::match_extra); The result is "y". Am I doing something wrong or have I found a bug? I'm using the latest stable 1_44_0 release compiled from source in VC9 and I also tried the pre-compiled library (http://sourceforge.net/projects/boost/files/boost-binaries/1.44.0/libboost_r...). The OS is Windows 7. Thanks for the help!

Am I doing something wrong or have I found a bug? I'm using the latest stable 1_44_0 release compiled from source in VC9 and I also tried the pre-compiled library (http://sourceforge.net/projects/boost/files/boost-binaries/1.44.0/libboost_r...). The OS is Windows 7.
You found a bug - it's been fixed in Trunk, and will be fixed in 1.45. As you note the alternative syntaxes for \k do work - basically there are so many different ways of doing the same thing that I missed that one :-( John.

On 11/4/2010 4:12 AM, John Maddock wrote:
Am I doing something wrong or have I found a bug? I'm using the latest stable 1_44_0 release compiled from source in VC9 and I also tried the pre-compiled library (http://sourceforge.net/projects/boost/files/boost-binaries/1.44.0/libboost_r...). The OS is Windows 7.
You found a bug - it's been fixed in Trunk, and will be fixed in 1.45. As you note the alternative syntaxes for \k do work - basically there are so many different ways of doing the same thing that I missed that one :-(
John. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Yeah, it's too bad too few of the regex libraries bothered to look at eachother and use the same syntax... I think I found another bug in that C:\Users\John\Downloads\!Software\Boost C libraries\boost_1_44_0\libs\regex> nmake -fvc9.mak builds libraries with a -1_42 extension instead of a -1_44 extension. I renamed one to 1_44 and it worked. Probably another case of too many ways to do the same thing (compile). Thanks for the quick reply! -- Chris Dragon Dracoventions Software Developer of the 2empowerFM family of plug-ins for FileMaker® Pro and Server. cdragon@dracoventions.com www.dracoventions.com
participants (2)
-
Chris Dragon
-
John Maddock