Prashant Agrawal Prashant Agrawal - 2 years ago 131
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 Source

Make it non-greedy as

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

Regex Demo

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download