Prashant Agrawal Prashant Agrawal - 7 months ago 27
Javascript Question

Extract data between characters using regex?

I have a string something like

[[user.system.first_name]][[user.custom.luid]] blah blah


I want to match
user.system.first_name
and
user.custom.luid


I built
/\[\[(\S+)\]\]/
but it is matching
user.system.first_name]][[user.custom.luid
.

Any idea where I am doing wrong?

Answer

Make it non-greedy as

/\[\[(\S+?)\]\]/

Regex Demo