![](/img/trans.png)
[英]Regex to get the string between a character and a whitespace and excluding the first delimiter
[英]Regex to get part from delimiter to end of the string excluding that delimiter
得到了類似於somedomen.com/path::targettext/with/params
字符串,並嘗試僅獲取沒有 ::
somedomen.com/path::targettext/with/params
targettext/with/params
,如果找不到分隔符,則不匹配。
使用/:{2}.*$
返回帶定界符的文本( ::targettext/with/params
/:{2}.*$
::targettext/with/params
)
如果沒有分隔符,則使用/(?!=::)[^:]*$
返回整個字符串。
使用Javascript。
有人可以幫忙嗎?
您可以在javascript中嘗試此方法,也可以在任何語言中使用:
.*?::(.*)$
您在第1組中獲得了理想的結果
const regex = /.*?::(.*)$/gm; const str = `somedomen.com/path::targettext/with/params`; let m; if((m = regex.exec(str)) !== null) { console.log(m[1]); }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.