Assume I have the following URL stored in variable called content
:
http://www.example.com/watch?v=4444444&feature=related
Problem:
The final output would look like:
http://www.example.com/embed/4444444
I tried these two steps but didn't work:
content = content.replace('/watch?v=/', 'embed/');
content = content.replace('&*/g','');
The URL in page source code appears as:
http://www.example.com/watch?v=4444444&feature=related
You have many errors:
'.*'
, not just '*'
. The star modifies the previous token. g
flag here. Try this instead:
content = content.replace('watch?v=', 'embed/').replace(/&.*/, '');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.