簡體   English   中英

如何驗證使用正則表達式開頭和不開頭?

[英]How to validate Starts with and Not Starts using Regular Expression?

我希望找到一種方法來組合兩個滿足以下條件的正則表達式:

  1. 以/ home /開頭
  2. 不以/ home / index開頭

對於第一種情況,我認為這可行:'^ / home /'

我不確定第二種情況的正則表達式應該是什么。

如果支持,可以實施負前瞻。

^/home/(?!index).*$

說明:

^           # the beginning of the string
/home/      # '/home/'
(?!         # look ahead to see if there is not:
  index     #   'index'
)           # end of look-ahead
.*          # any character except \n (0 or more times)
$           # before an optional \n, and the end of the string

現場演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM