- // Note that '[' and '\' must be escaped.
- // This is a limitation of boost::regex, but all other chars in BREs
- // are assumed literal.
- boost::regex reg("[].|*?+(){}^$\\[\\\\]");
-
- // $& is a perl-like expression that expands to all of the current match
- // The '$' must be prefixed with the escape character '\' for
- // boost to treat it as a literal.
- // Thus, to prefix a matched expression with '\', we use:
- return boost::regex_replace(expr, reg, "\\\\$&");
+ // Note that '[', ']', and '\' must be escaped.
+ lyx::regex reg("[.|*?+(){}^$\\[\\]\\\\]");
+
+ // $& is a ECMAScript format expression that expands to all
+ // of the current match
+#if defined(LYX_USE_CXX11) && defined(LYX_USE_STD_REGEX)
+ // To prefix a matched expression with a single literal backslash, we
+ // need to escape it for the C++ compiler and use:
+ return lyx::regex_replace(expr, reg, "\\$&");
+#else
+ // A backslash in the format string starts an escape sequence in boost.
+ // Thus, to prefix a matched expression with a single literal backslash,
+ // we need to give two backslashes to the regex engine, and escape both
+ // for the C++ compiler and use:
+ return lyx::regex_replace(expr, reg, "\\\\$&");
+#endif