-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);
2
  • What error did you have? Commented Jun 13, 2018 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 Commented Jun 13, 2018 at 12:20

1 Answer 1

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));


Sign up to request clarification or add additional context in comments.

3 Comments

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';
@MahmutDuman I've edited my post with a multiple video outcome :)
Ow Thanks its awesome and worked for me :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.