diff --git a/autotests/folding/d399388_dynamic_RegExpr.dyInclRl.fold b/autotests/folding/d399388_dynamic_RegExpr.dyInclRl.fold
new file mode 100644
--- /dev/null
+++ b/autotests/folding/d399388_dynamic_RegExpr.dyInclRl.fold
@@ -0,0 +1,2 @@
+normal X:string other: normal X:string other: normal
+normal X{string other} normal X:string other: normal
diff --git a/autotests/html/d399388_dynamic_RegExpr.dyInclRl.html b/autotests/html/d399388_dynamic_RegExpr.dyInclRl.html
new file mode 100644
--- /dev/null
+++ b/autotests/html/d399388_dynamic_RegExpr.dyInclRl.html
@@ -0,0 +1,9 @@
+
+
+
+d399388_dynamic_RegExpr.dyInclRl
+
+
+normal X:string other: normal X:string other: normal
+normal X{string other} normal X:string other: normal
+
diff --git a/autotests/input/d399388_dynamic_RegExpr.dyInclRl b/autotests/input/d399388_dynamic_RegExpr.dyInclRl
new file mode 100644
--- /dev/null
+++ b/autotests/input/d399388_dynamic_RegExpr.dyInclRl
@@ -0,0 +1,2 @@
+normal X:string other: normal X:string other: normal
+normal X{string other} normal X:string other: normal
diff --git a/autotests/input/syntax/d399388_dynamic_RegExpr.xml b/autotests/input/syntax/d399388_dynamic_RegExpr.xml
new file mode 100644
--- /dev/null
+++ b/autotests/input/syntax/d399388_dynamic_RegExpr.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/autotests/reference/d399388_dynamic_RegExpr.dyInclRl.ref b/autotests/reference/d399388_dynamic_RegExpr.dyInclRl.ref
new file mode 100644
--- /dev/null
+++ b/autotests/reference/d399388_dynamic_RegExpr.dyInclRl.ref
@@ -0,0 +1,2 @@
+normal X:string other: normal X:string other: normal
+normal X{string other} normal X:string other: normal
diff --git a/src/lib/rule.cpp b/src/lib/rule.cpp
--- a/src/lib/rule.cpp
+++ b/src/lib/rule.cpp
@@ -613,51 +613,51 @@
/**
* no match
*/
- return MatchResult(offset, result.capturedStart());
+ return MatchResult(offset, m_dynamic ? 0 : result.capturedStart());
}
bool StringDetect::doLoad(QXmlStreamReader& reader)
{
m_string = reader.attributes().value(QStringLiteral("String")).toString();
m_caseSensitivity = Xml::attrToBool(reader.attributes().value(QStringLiteral("insensitive"))) ? Qt::CaseInsensitive : Qt::CaseSensitive;
m_dynamic = Xml::attrToBool(reader.attributes().value(QStringLiteral("dynamic")));
return !m_string.isEmpty();
}
MatchResult StringDetect::doMatch(const QString& text, int offset, const QStringList &captures) const
{
/**
* for dynamic case: create new pattern with right instantiation
*/
const auto &pattern = m_dynamic ? replaceCaptures(m_string, captures, false) : m_string;
if (text.midRef(offset, pattern.size()).compare(pattern, m_caseSensitivity) == 0)
return offset + pattern.size();
return offset;
}
bool WordDetect::doLoad(QXmlStreamReader& reader)
{
m_word = reader.attributes().value(QStringLiteral("String")).toString();
m_caseSensitivity = Xml::attrToBool(reader.attributes().value(QStringLiteral("insensitive"))) ? Qt::CaseInsensitive : Qt::CaseSensitive;
return !m_word.isEmpty();
}
MatchResult WordDetect::doMatch(const QString& text, int offset, const QStringList &) const
{
if (text.size() - offset < m_word.size())
return offset;
if (offset > 0 && !isWordDelimiter(text.at(offset - 1)))
return offset;
if (text.midRef(offset, m_word.size()).compare(m_word, m_caseSensitivity) != 0)
return offset;
if (text.size() == offset + m_word.size() || isWordDelimiter(text.at(offset + m_word.size())))
return offset + m_word.size();
return offset;
}