我有一个看起来像这样的网址:/events/eventID/something
我该如何匹配eventID
无论eventID有多长,它都应该起作用。
有人可以帮助我吗?
答案 0 :(得分:-2)
您可以使用前瞻:
x(?=y) – positive lookahead (matches 'x' when it's followed by 'y')
x(?!y) – negative lookahead (matches 'x' when it's not followed by 'y')
,您还可以使用lookbehinds:
(?<=y)x – positive lookbehinds (matches 'x' when it's precede by 'y')
(?<!y)x – negative lookbehinds (matches 'x' when it's not precede by 'y')
您的情况的示例:
/(?<=.\/)[^\/]+(?=\/)/
或
(?<=.\/).+(?=\/)