正则表达式:(?!...)是什么意思? [英] Regex: what does (?! ...) mean?

查看:952
本文介绍了正则表达式:(?!...)是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下正则表达式在子字符串FTW和ODP之间查找文本.

The following regex finds text between substrings FTW and ODP.

/FTW(((?!FTW|ODP).)+)ODP+/

(?! ... )的作用是什么?

What does the (?!...) do?

推荐答案

(?!regex)零宽度负前瞻.它将测试当前光标位置处的字符并向前移动,测试它们与提供的正则表达式匹配,然后将光标返回到其开始位置.

(?!regex) is a zero-width negative lookahead. It will test the characters at the current cursor position and forward, testing that they do NOT match the supplied regex, and then return the cursor back to where it started.

整个正则表达式:

/
 FTW           # Match Characters 'FTW'
 (             # Start Match Group 1
  (             # Start Match Group 2
   (?!FTW|ODP)   # Ensure next characters are NOT 'FTW' or 'ODP', without matching
   .             # Match one character
  )+            # End Match Group 2, Match One or More times
 )             # End Match Group 1
 OD            # Match characters 'OD'
 P+            # Match 'P' One or More times
/

所以-寻找FTW,然后在寻找ODP+结束时捕获.另外,请确保FTWODP+之间的数据不包含FTWODP

So - Hunt for FTW, then capture while looking for ODP+ to end our string. Also ensure that the data between FTW and ODP+ doesn't contain FTW or ODP

这篇关于正则表达式:(?!...)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆