Adam Schwarcz
Adam Schwarcz

Reputation: 487

Regex – Get string after a character

I have this code which works for getting the part of the string BEFORE a character (in my case the character is ":")

var getMinutes = value.match(/([\d.]+) *:/)[1];

I need to make it work for getting the part of string after ":" too but im stuck

Upvotes: 0

Views: 50

Answers (2)

You can try split. For example: value = "123:456" => value.split(":")[0] will return "123" while value.split(":")[1] will return "456"

Upvotes: 0

Barmar
Barmar

Reputation: 782488

Move the capture group to after the :

var getSeconds = value.match(/[\d.]+ *:([\d.]+)/)[1];

Upvotes: 2

Related Questions