Regex: what does (?! …) mean?

前端 未结 6 1572
既然无缘
既然无缘 2021-02-12 21:46

The following regex finds text between substrings FTW and ODP.

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

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

6条回答
  •  再見小時候
    2021-02-12 22:31

    Regex

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

    matches first FTW immediately followed neither by FTW nor by ODP, then all following chars up to the first ODP (but if there is FTW somewhere in them there will be no match) then all the letters P that follow.

    So in the string:

    FTWFTWODPFTWjjFTWjjODPPPPjjODPPPjjj

    it will match the bold part

    FTWFTWODPFTWjjFTWjjODPPPPjjODPPPjjj

提交回复
热议问题