![](/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.