[英]Match string only if not followed by another specific string
I have #[\\s]+on[az]+[\\s]*=#si
. 我
#[\\s]+on[az]+[\\s]*=#si
有#[\\s]+on[az]+[\\s]*=#si
。 I need to match ( preg_replace ) string like onclick =
but only if this string isn't followed by another specific string. 我需要匹配( preg_replace )字符串,如
onclick =
但仅当此字符串后面没有其他特定字符串时。
Example (bold is the match) 示例(粗体是匹配)
some text onClickOrWhatever = some text
一些文字onClickOrWhatever =一些文字
some text onClickOrWhatever = my special string some text
一些文字onClickOrWhatever =我的特殊字符串一些文字
Second line shouldn't be matched because the expression is follow by "my special string". 第二行不应该匹配,因为表达式后跟“我的特殊字符串”。 In another words, I need to keep intact specific inline javascript but remove(destroy) any other.
换句话说,我需要保持完整的特定内联JavaScript,但删除(销毁)任何其他。
This expression is a little too general. 这个表达有点过于笼统。 It would also partially match
you told me once =)
, I am aware of that. 它也会部分匹配
you told me once =)
,我知道这一点。
Well to answer your question, you can use negative lookahead
: 那么回答你的问题,你可以使用
negative lookahead
:
#\s+on[a-z]+\s*=(?!\s*my special string)#i
You also don't need s
flag here which is used for making DOT
match newline
. 你也不需要在这里用于制作
DOT
匹配newline
s
标志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.