views:

50

answers:

2

Hi,

I asked a question about regular expression in PHP (which got answered), I need help with same regular expression in javascript, here is the link to previous question. http://stackoverflow.com/questions/2015320/need-help-with-writing-regular-expression

Again I am not looking to get JSON.parse and get the json object, I need to find the regex for the pattern.

Thanks

A: 

Try something like:

var matches = text.match(/\[\[.*?\]\]/);

matches[0] will be the matched string.

Since the DOTALL PCRE option isn't supported in Javascript, you'd have to use a regular expression like that:

var matches = text.match(/\[\[(?:\s|.)*?\]\]/);
watain
Thanks, it helped, my mistake was that I was using quotes around pattern.
nutalk
You can actually use quotes in JS too, using the object construct `RegExp`, like f.e. `myRegExp = new RegExp("[a-z]+",options)` and then using the generated regular expression with `match`: `matches = text.match(myRegExp)`.
watain
A: 
/\[\[.*?\]\]/g

G - Global (find more than once)

Justin Johnson
`/m enables "multi-line mode". In this mode, the caret and dollar match before and after newlines in the subject string.`. Thus, isn't the `m` option senseless?
watain
Yes, I removed that flag.
Justin Johnson