-1

when i trying this match im getting links like this;

Result:

"video","src":"https:\/\/video-mxp1-1.xx.fbcdn.net\/v\/t42.9040-2\/34384597_178997956146914_227512178675023872_n.mp4"

I want get just cleaned link like this:https:\/\/video-mxp1-1.xx.fbcdn.net\/v\/t42.9040-2\/34384597_178997956146914_227512178675023872_n.mp4

Thanks for your helps; My codes are below:

var VideoLinks='"type":"video","src":"https:\\\/\\\/video-mxp1-1.xx.fbcdn.net\\\/v\\\/t42.9040-2\\\/34333324_n.mp4?_nc_cat=0&efg=ey1&oe=5B211DB0","width":null"type":"video","src":"https:\\\/\\\/video-mxp1-1.xx.fbcdn.net\\\/v\\\/t42.9040-2\\\/34333324_n.mp4?_nc_cat=0&efg=ey1&oe=5B211DB0","width":null';

My Pattern
pattern =/"video","src":"(.*?)"/g;
var videos=Sitestring.match(pattern);
console.log(videos);
Mahmut Duman
  • 407
  • 1
  • 5
  • 12
  • What error did you have? –  Jun 13 '18 at 12:15
  • Not eror , im getting links via "video","src":" text but i dont want this text , i want just cleaned link like; https:\\\/\\\/video-mxp1-1.xx.fbcdn.net\\\/v\\\/t42.9040-2\\\/34333324_1111077645701352_5020419359995068416_n.mp4 not:"video","src":"https:\\\/\\\/video-mxp1-1.xx.fbcdn.net\\\/v\\\/t42.9040-2\\\/34333324_1111077645701352_5020419359995068416_n.mp4 – Mahmut Duman Jun 13 '18 at 12:20

1 Answers1

3

const str = '"video","src":"https:\vid1.mp4"';

const regex = new RegExp('src\":\"(.*)\"', 'i');

console.log(regex.exec(str)[1]);

And about multiple occurences

function getMatch(str, regex) {
  const matches = [];

  let oneMatch;

  do {
    oneMatch = regex.exec(str);

    if (!oneMatch) {
      return matches;
    }

    matches.push(oneMatch[1]);
  } while (oneMatch);
}

const str = '"video","src":"https:vid1.mp4","video","src":"https:vid2.mp4","video","src":"https:vid3.mp4"';

const regex = new RegExp('src\":\"(.*?)\"', 'ig');

console.log(getMatch(str, regex));

Orelsanpls
  • 22,456
  • 6
  • 42
  • 69
  • 1
    Thanks your ansver but im loking fix this in a 1 match is it possible ? var VideoLinks='"type":"video","src":"https:\\\/\\\/video-mxp1-1.xx.fbcdn.net\\\/v\\\/t42.9040-2\\\/34333324_n.mp4?_nc_cat=0&efg=ey1&oe=5B211DB0","width":null"type":"video","src":"https:\\\/\\\/video-mxp1-1.xx.fbcdn.net\\\/v\\\/t42.9040-2\\\/34333324_n.mp4?_nc_cat=0&efg=ey1&oe=5B211DB0","width":null'; – Mahmut Duman Jun 13 '18 at 12:37
  • @MahmutDuman I've edited my post with a multiple video outcome :) – Orelsanpls Jun 13 '18 at 12:55
  • Ow Thanks its awesome and worked for me :) – Mahmut Duman Jun 13 '18 at 13:03