I have following code:
this.parse = function(whatToParse, currentItem) {
var re = /\{j\s([a-z0-9\.\|_]+)\ss\}/gi;
var newResult = whatToParse.replace(re, function(matches){
alert(matches);
});
}
whatToParse is:
<h1>
{j name s}
</h1>
<div>
<nobr>{j description s}</nobr>
</div>
But why matches is not array? It contains only matched string, without groups.
For example: alert(matches); alerts “{j name s}” and alert(matches[1]); alerts “j”.
Why? How to get first group?
P.S. I don’t understand it, because in PHP this RegExp works correctly.
See the documentation [MDN]. The captured values are passed as arguments to the function.
(sorry for the formatting, but creating tables in Markdown is not easy)
So in your case: