0

I need to figure out a way to get part of a string by providing common sting match. The code is set up at: http://jsfiddle.net/rexonms/0s7cgxku/

Javascript
----------

findIds(txt);

var ids = [];
var txt = "And all I need is the fan-page-id-xx and also the fan-page-id-yy but not fan-page."


function findIds(txt){

   var word = txt.match(/fan-page-id/m); //how do I get the ids (xx, yy) from here?
   var id = 'x';
   ids.push(id);
   console.log(ids)
}
rex
  • 985
  • 5
  • 28
  • 48
  • 1
    See https://regex101.com/r/uQ2nC7/1 Is it what you were looking for? – PM 77-1 Jan 28 '15 at 00:14
  • @PM77-1 yep. That's awesome. That's a kick ass way to do it :) – rex Jan 28 '15 at 00:23
  • 1
    By using the regex suggested by @PM77-1, you can get all the xx and yy value in ids by using looping the match value http://jsfiddle.net/zeskysee/hqcmkx0v/ – Zesky Jan 28 '15 at 01:31
  • @Zesky - Yes, this seems to be [the way](http://stackoverflow.com/questions/432493/how-do-you-access-the-matched-groups-in-a-javascript-regular-expression) to do it. – PM 77-1 Jan 28 '15 at 01:57

0 Answers0