繁体   English   中英

什么正则表达式匹配“:”之前的字符串

[英]what regex match strings of characters before ":"

文本示例:

Some string here : my value
Another string : my value
String : my value

我想匹配之前的所有内容,包括符号:

我想要的输出是:

Some string here : 
Another string : 
String : 

谢谢

只需使用:

(.* :)

参见示例: https : //regex101.com/r/bA1cQ1/2

不要使用正则表达式,因为它不是正则表达式的锤子的钉子

 var strToMatch = "Some string here : my value"; var match = strToMatch.slice(0,strToMatch.indexOf(':')+1); // do something with the match document.body.appendChild(document.createElement('pre')).innerHTML = match;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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