使用VBA正则expression式来标识不包含特定单词的string
使用VBA Regular Expresions,我试图在Excel中查找包含string“CK”并且不包含string“AS”的单元格,但它始终阻止以A或S开头的任何string。我正在使用以下expression:
pattern1 = "^[^AS](.*)CK(.*)"
我曾经看到负面的预测被build议,但是我所见过的(主要是其他编程语言)没有任何build议的expression式不能用于VBA-Excel。
任何提示?
没有断言可以这样做(但是很难):
'the idea is that it should contain CK but it should not contain AS in the very beginning'
^(?:A[^SC].*CK|AC[^K].*CK|ACK|CK|[^A].*CK).*$
格式化
^ (?: A [^SC] .* CK | AC [^K] .* CK | ACK | CK | [^A] .* CK ) .* $
或者,不在string中的任何地方
^(?:[^A]|A[^S])*(?:ACK|CK)(?:[^A]|A(?:[^S]|$))*$
格式化
^ (?: [^A] | A [^S] )* (?: ACK | CK ) (?: [^A] | A (?: [^S] | $ ) )* $
试试这个模式
^(?!AS).*CK.*