KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I need to parse several pages to get all of their Youtube IDs. I found many regular expressions on the web, but : the Java ones are not complete (they either give me garbage in addition to the IDs, or they miss some IDs). The one that I found that seems to be complete is hosted here . But it is written in JavaScript and PHP. Unfortunately I couldn't translate them into JAVA. Can somebody help me rewrite this PHP regex or the following JavaScript one in Java? '~ https?:// # Required scheme. Either http or https. (?:[0-9A-Z-]+\.)? # Optional subdomain. (?: # Group host alternatives. youtu\.be/ # Either youtu.be, | youtube\.com # or youtube.com followed by \S* # Allow anything up to VIDEO_ID, [^\w\-\s] # but char before ID is non-ID char. ) # End host alternatives. ([\w\-]{11}) # $1: VIDEO_ID is exactly 11 chars. (?=[^\w\-]|$) # Assert next char is non-ID or EOS. (?! # Assert URL is not pre-linked. [?=&+%\w]* # Allow URL (query) remainder. (?: # Group pre-linked alternatives. [\'"][^<>]*> # Either inside a start tag, | </a> # or inside <a> element text contents. ) # End recognized pre-linked alts. ) # End negative lookahead assertion. [?=&+%\w]* # Consume any URL (query) remainder. ~ix' /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w]*(?:['"][^<>]*>|<\/a>))[?=&+%\w]*/ig;
Tags (comma-separated)
Save Edits
Cancel