我正在尝试转义以下正则表达式
(<t:Message>)[\s\S]*?(<\/t:Message>)
在我的 ABAP 源代码中使用它。
到目前为止我得到的只是以下内容:
(<t:Message>)[\\s\\S]\*?(<\/t:Message>)
但由于某种原因,它没有给出预期的结果。
这里是否有任何正则表达式专家可以帮助我转义这个正则表达式,以便我可以在 ABAP 中使用它?我将非常感激。
最佳答案
您的表达式有两个主要问题,其中任何一个都与转义无关。
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>)
至少在语法上是正确的 - 它是否能满足您的要求还不清楚,因为您一开始就没有指定您需要什么。
关于regex - ABAP 中正则表达式的正确转义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45506781/