繁体   English   中英

正则表达式从分隔符到字符串末尾的部分,不包括该分隔符

[英]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。

有人可以帮忙吗?

只需尝试以下模式:

/::(.*$)/ 

然后$1包含您所需要的。

在线演示

您可以在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM