什么正则表达式匹配":&"

what regex match strings of characters before ":"

本文关键字:quot 正则表达式 什么      更新时间:2023-09-26

文本示例:

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;