0
var text = "{templateUrl: 'conversations/conversations.tpl.html',";
var result = text.match(/templateUrl:(\s*['"]\S*['"])/g);

I want result to be 'conversations/conversations.tpl.html' but I am getting "templateUrl: 'conversations/conversations.tpl.html'".

I have checked it here: http://regex101.com/r/uW1vY6 and it does what I expect, but not in the console or in a real program.

What am I doing wrong?

kpg
  • 7,644
  • 6
  • 34
  • 67
  • possible duplicate of [Javascript Regex and Submatches](http://stackoverflow.com/questions/844001/javascript-regex-and-submatches) – Barmar Mar 12 '14 at 09:49

1 Answers1

0

this is exactly how you get the matched groups from the regex

var text = "{templateUrl: 'conversations/conversations.tpl.html',";
var myRegexp = /templateUrl:(\s*['"]\S*['"])/g;
var match = myRegexp.exec(text);
alert(match[1]);

try this

var text = "{templateUrl: 'conversations/conversations.tpl.html',";
var result = text.match(/\'(.*)\'/)[0];
console.log(result);
aelor
  • 10,892
  • 3
  • 32
  • 48