在 ABAP 中正确转义正则表达式
proper escaping of regex in ABAP
我正在尝试转义以下正则表达式
(<t:Message>)[\s\S]*?(<\/t:Message>)
在我的 ABAP 源代码中使用它。
到目前为止我得到的是以下内容:
(<t:Message>)[\s\S]\*?(<\/t:Message>)
但出于某种原因,它没有给出预期的结果。
这里是否有任何正则表达式专家可以帮助我转义这个正则表达式,以便我可以在 ABAP 中使用它?我将不胜感激。
您的表达有两个主要问题,none 其中与转义完全有关。
The special characters \w, \u, \l, \d, and \s can also be specified
within sets [...]. Use of the special characters \W, \U, \L, \D, and
\S within sets is not permitted and raises the exception
CX_SY_INVALID_REGEX.
(引自 documentation) - 所以用其他东西替换它,比如 .*
The regular expressions r{n,m}?, r*? and r+? are reserved for future
language enhancements (non-greedy behavior) and currently raise the
exception CX_SY_INVALID_REGEX.
(引自 documentation) - 所以不要使用 *?
(<t:Message>).*(</t:Message>)
至少在语法上是正确的——它是否做你想要的还不清楚,因为你没有首先指定你需要什么。
我正在尝试转义以下正则表达式
(<t:Message>)[\s\S]*?(<\/t:Message>)
在我的 ABAP 源代码中使用它。
到目前为止我得到的是以下内容:
(<t:Message>)[\s\S]\*?(<\/t:Message>)
但出于某种原因,它没有给出预期的结果。
这里是否有任何正则表达式专家可以帮助我转义这个正则表达式,以便我可以在 ABAP 中使用它?我将不胜感激。
您的表达有两个主要问题,none 其中与转义完全有关。
The special characters \w, \u, \l, \d, and \s can also be specified within sets [...]. Use of the special characters \W, \U, \L, \D, and \S within sets is not permitted and raises the exception CX_SY_INVALID_REGEX.
(引自 documentation) - 所以用其他东西替换它,比如 .*
The regular expressions r{n,m}?, r*? and r+? are reserved for future language enhancements (non-greedy behavior) and currently raise the exception CX_SY_INVALID_REGEX.
(引自 documentation) - 所以不要使用 *?
(<t:Message>).*(</t:Message>)
至少在语法上是正确的——它是否做你想要的还不清楚,因为你没有首先指定你需要什么。