From cc0c58839f9da2fb9ec24d075a6359a979ffcb26 Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Sun, 30 Sep 2018 18:37:55 +0200 Subject: [PATCH] Amend(3) 73188e3 Adapt the positional references in regex supplied by user so that for instance '([a-z]+)\s\1' to find identical words in sequence is changed to '([a-z]+)\s\2'. --- src/lyxfind.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 8a48ec9991..40e943f24b 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -951,13 +951,23 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const & // If entered regexp must match at begin of searched string buffer // Kornel: Added parentheses to use $1 for size of the leading string - string regexp_str = "(" + lead_as_regexp + ")" + par_as_string; + string regexp_str; + string regexp2_str; + { + // TODO: Adapt '\[12345678]' in par_as_string to acount for the first '() + // Unfortunately is '\1', '\2', etc not working for strings with extra format + // so the convert has no effect in that case + for (int i = 8; i > 0; --i) { + string orig = "\\\\" + std::to_string(i); + string dest = "\\" + std::to_string(i+1); + while (regex_replace(par_as_string, par_as_string, orig, dest)); + } + regexp_str = "(" + lead_as_regexp + ")" + par_as_string; + regexp2_str = "(" + lead_as_regexp + ").*" + par_as_string; + } LYXERR(Debug::FIND, "Setting regexp to : '" << regexp_str << "'"); regexp = lyx::regex(regexp_str); - // If entered regexp may match wherever in searched string buffer - // Kornel: Added parentheses to use $1 for size of the leading string - string regexp2_str = "(" + lead_as_regexp + ").*" + par_as_string; LYXERR(Debug::FIND, "Setting regexp2 to: '" << regexp2_str << "'"); regexp2 = lyx::regex(regexp2_str); } -- 2.39.5