正则表达式中的单引号和反引号

B. *_*les 2 regex abap posix pattern-matching

我正在尝试匹配字符串中的单引号,如果存在,我想使用WRITE.

    data text type string value `this is a string containing a ' single quote`.
    find regex `(\'|%27)` in text.
    if sy-subrc = 0.
      write 'found'.
    endif.
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是我不了解 ABAP 正则表达式中反引号字符的行为。并且无法在网上找到资源并解释其工作原理。我使用它的结果很奇怪,这取决于匹配项上方的 TEXT 字符串是有效还是失败。

在 PERL 中,您可以执行诸如在字符串中搜索字符串变量之类的操作,例如/:

    data text type string value `this is a string containing a ' single quote`.
    find regex `(\'|%27)` in text.
    if sy-subrc = 0.
      write 'found'.
    endif.
Run Code Online (Sandbox Code Playgroud)

这种方法可以在 ABAP 中使用吗,或者有人可以解释如何在 ABAP 中使用反引号?

Est*_*sti 5

在这种情况下您不需要反引号,但是我认为您正在寻找的是转义字符以表明 ' 是字符串/正则表达式的一部分

data text type string value `this is a string containing a '' single quote`.
    find regex `(''|%27)` in text.
    if sy-subrc = 0.
    write 'found'.
    endif.
Run Code Online (Sandbox Code Playgroud)

注意定义的字符串和正则表达式中的额外 '。

编辑:为了回应您对文档的评论,如果您将光标定位在正则表达式一词上执行 F1(帮助),您应该能够访问正则表达式的 SAP 帮助。看起来大部分语法都记录在那里。(或者,只需按 F1 并搜索正则表达式)。