如何对特定匹配项中不存在的点符号(例如,图像HTML标记中)执行正则表达式替换
str = "Hi. the symbol before me is my match target <img src='http://skip.these.dots/and.this.as.well' alt='me.three' /> but still match this."
用(例如)*符号代替
res = "Hi* the symbol before me is my match target <img src='http://skip.these.dots/and.this.as.well' alt='me.three' /> but still match this*"
尝试这个:
\.(?![^<]*\/>)
正则表达式引擎执行以下操作。
\. # match period
(?! # begin negative lookahead
[^<]* # match 0+ chars other than '<'
\/> # match '/>'
)
如果/>
在时间段之后没有任何干预地遇到负向前瞻,则失败<
,这意味着时间段必须介于a<
和an之间/>
。
您希望将的每个匹配项替换为*
。具体操作方式取决于您使用的语言,但这无疑很简单。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句