Regex delete everything after: (including :)

Hi everyone, I have a line like: "Foundation: 100"

I want to use the JS regex to remove everything after: include (:)

Thanks for any help!

+7
source share
2 answers
var text = "Foundation: 100"; text = text.replace(/:.*$/,""); console.log(text); 
+12
source

As an example, you can call .split(":") on your line, and then select the first element of the array using "[0]"

 var whole_text = "Foundation: 100"; var wanted_text = whole_text.split(":")[0] console.log(wanted_text) 
+3
source

All Articles