I just spent an hour delving into the possible differences between \g and \k, of which there are no satisfactory answers, and a few wrong answers. This eventually led me to digging into Boost's source code.
The short explanation is that there is no difference between \g and \k other than the history behind each.
Boost's source code treats them identically: regex_traits_defaults.hpp maps both characters to the exact same internal token:
escape_type_extended_backref, /*g*/
...
escape_type_extended_backref, /*k*/
...and basic_regex_parser.hpp has one single case for escape_type_extended_backref. It never checks if the original character was g or k.
After digging a little more, it turns out it's just a historical choice based on Perl's implementation that Boost chose to extend.
For this reason, I think it would be worthwhile mentioning this in the documentation.
My proposed change would be to add the following under the Capture Groups and Backreferences section of the Searching page:
\g and \k are functionally synonymous prefixes for extended backreferences. There is no semantic difference in Boost's implementation. They coexist for syntax-compatibility/historical reasons.
I'm about to make a PR for this change.
I just spent an hour delving into the possible differences between
\gand\k, of which there are no satisfactory answers, and a few wrong answers. This eventually led me to digging into Boost's source code.The short explanation is that there is no difference between
\gand\kother than the history behind each.Boost's source code treats them identically: regex_traits_defaults.hpp maps both characters to the exact same internal token:
...and basic_regex_parser.hpp has one single case for
escape_type_extended_backref. It never checks if the original character wasgork.After digging a little more, it turns out it's just a historical choice based on Perl's implementation that Boost chose to extend.
For this reason, I think it would be worthwhile mentioning this in the documentation.
My proposed change would be to add the following under the Capture Groups and Backreferences section of the
Searchingpage:I'm about to make a PR for this change.