javascript - Optional ending capture group -


i'm trying have 3 total capture groups last optional. i'm running issue i'm not sure how exclude last delimiter last group , have end.

here's pattern

/(.+)\@(.+)\:(.+)/ 

here's example strings

test@hello // => ['test', 'hello'] test@hello:optional // => ['test', 'hello', 'optional'] 

use string.split

string.split(/[:@]/) 

[:@] matches colon or @ symbol split function splits string according matched chars.

var s = 'test@hello:optiona'  alert(s.split(/[@:]/))

or

var s = 'test@hello:optiona'  alert(s.match(/[^@:]+/g))


Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -