There is a content string that includes full YouTube URLs and video IDs. I need to replace the URLs with just the video IDs. The example of the "content" variable:
var content = '{GENERICO:type="youtube",id="DluFA_AUjV8"}{GENERICO:type="youtube",id="https://youtu.be/DluFA_AUjV8"}';
var myRegex = /{GENERICO:type="youtube",id=".*?(?:youtube\.com|youtu\.be)\/(?:embed\/|watch\?v\=)?([^\&\?\/\"]+).*?["&\?]}/gi;
content = content.replace(myRegex, '{GENERICO:type="youtube",id="$1"}' );
console.log(content);
The desired result (in the example) is:
{GENERICO:type="youtube",id="DluFA_AUjV8"}{GENERICO:type="youtube",id="DluFA_AUjV8"}
However, the actual output is:
The desired result (in the example) is:
{GENERICO:type="youtube",id="DluFA_AUjV8"}
It seems to be removing one of the strings in the content but I can't pinpoint if it's a JavaScript or regex issue.
Here is the JsFiddle link