我试图在文本中捕获仅在匹配后没有特定字符时才匹配的组,在这种情况下,左括号“(”表示“函数/方法”而不是“属性”的开始。
这看起来很简单,所以我试过:
TEXT
$this->willMatch but $this->willNot()
RESULT
RegExp pattern: \$this->[a-zA-Z0-9\_]+(?<!\()
Expected: $this->willMatch
Actual: $this->willMatch, $this->willNot
RegExp pattern: \$this->[a-zA-Z0-9\_]+[^\(]
Expected: $this->willMatch
Actual: $this->willMatch, $this->willNot
RegExp pattern: \$this->[a-zA-Z0-9]+(?!\()
Expected: $this->willMatch
Actual: $this->willMatch, $this->willNo
Run Code Online (Sandbox Code Playgroud)
我的直觉是我需要添加 ^ 和 $ 但这不适用于文本中的多次出现。
很想认识可以解决这个问题的 RegExp 向导!
regex ×1