मुझे अपने सभी यूट्यूब आईडी प्राप्त करने के लिए कई पृष्ठों को पार्स करने की आवश्यकता है।यूट्यूब पूर्ण जावा रेगेक्स
मुझे वेब पर कई नियमित अभिव्यक्तियां मिलीं, लेकिन: जावा वाले पूर्ण नहीं हैं (वे या तो मुझे आईडी के अलावा कचरा देते हैं, या वे कुछ आईडी याद करते हैं)।
जो मुझे मिला वह पूरा होने लगता है here होस्ट किया गया है। लेकिन यह जावास्क्रिप्ट और PHP में लिखा है। दुर्भाग्य से मैं उन्हें जावा में अनुवाद नहीं कर सका।
क्या कोई मुझे जावा में इस PHP regex या निम्न जावास्क्रिप्ट को फिर से लिखने में मदद कर सकता है?
'~
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;
क्यों छोटे अक्षरों के लिए वैकल्पिक उप डोमेन की अनुमति नहीं है के अलावा एक ही है: ....
मैं एक अद्यतन है? आप उस भाग को '... [0-9A-Za-z -] ...' – eykanal
@eykanal में बदलना चाहते हैं, यह 'i' ध्वज का उपयोग कर रहा है। – Marcus
@ मर्कस - आह, अच्छी पकड़, रेगेक्स में बहुत आगे नहीं पढ़ी। – eykanal