Marius
Marius

Reputation: 171

How to parse some text from pattern with javascript?

the string contains a value like this:

my string [[ [[test1]] test2 ]] other text

How I can get a values test1 and test2 in a different variables?

I tried!

var test = "my string [[ [[test1]] test2 ]] other text";

var reg = /[^\[\]]*[\w ]+(?=\])/i;
var reg2 = /\]\]\s*(.*)\s*\]\]/i;

result = reg2.exec(test);

​alert(result);​

The second regular I've made by myself, but it's still not the answer, it's returns me an array. So how to make it only a one value instead of whole array?

Upvotes: 0

Views: 580

Answers (1)

burning_LEGION
burning_LEGION

Reputation: 13450

use this regular experssion [^\[\]]*[\w ]+(?=\])

Upvotes: 1

Related Questions