एक स्ट्रिंग के भीतर URL खोजने के लिए नियमित अभिव्यक्ति


94

क्या किसी को एक नियमित अभिव्यक्ति का पता है जिसका उपयोग मैं एक स्ट्रिंग के भीतर URL खोजने के लिए कर सकता हूं? मैंने यह निर्धारित करने के लिए Google पर बहुत सारे नियमित भाव पाए हैं कि यदि संपूर्ण स्ट्रिंग एक URL है, लेकिन मुझे URL के लिए संपूर्ण स्ट्रिंग खोजने में सक्षम होना चाहिए। उदाहरण के लिए, मैं ढूँढने में सक्षम होना चाहते हैं www.google.comऔर http://yahoo.comनिम्न स्ट्रिंग में:

Hello www.google.com World http://yahoo.com

मैं स्ट्रिंग में विशिष्ट URL की तलाश नहीं कर रहा हूं। मैं स्ट्रिंग में सभी URL की तलाश कर रहा हूं जिसके कारण मुझे एक नियमित अभिव्यक्ति की आवश्यकता है।


यदि आपके पास पूरे स्ट्रिंग के लिए भाव हैं, तो उन्हें स्ट्रिंग के कुछ हिस्सों से मिलान करने के लिए बस ^ और $ बाहर ले जाएं।
एंटोनियो

जवाबों:


205

यह वह है जिसका मैं उपयोग करता हूं

(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?

मेरे लिए काम करता है, आपके लिए भी काम करना चाहिए।


7
फॉरवर्ड स्लैश से बचना न भूलें।
मार्क

1
यह 2017 है, और यूनिकोड डोमेन नाम सभी जगह हैं। \wअंतरराष्ट्रीय प्रतीकों (रेगेक्स इंजन पर निर्भर करता है) से मेल नहीं खा सकता है, इसके बजाय सीमा की आवश्यकता है a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF:।
माइकल एंटीपिन

3
यह सामान्य प्रयोजन के लिए ठीक है, लेकिन कई मामले हैं जो इसे पकड़ नहीं पाते हैं। यह दर्शाता है कि आपके लिंक एक प्रोटोकॉल के साथ उपसर्ग कर रहे हैं। यदि प्रोटोकॉल को अनदेखा करना चुनते हैं, तो ईमेल के अंत को स्वीकार कर लिया जाता है क्योंकि यह test@testing.com के मामले में है।
स्क्वैज

4
नहीं [\w_-]होना चाहिए [\w-]? क्योंकि \wपहले से _ही मेल खाता है । प्रति मोज़िला डॉक्स
स्थानांतरित करें

2
अपवोट किया गया लेकिन यह उत्तर उस काम नहीं करता है जो प्रश्न पूछ रहा है www.yahoo.com"""(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?""".r.findAllIn("www.google.com").toList। उत्तर के लिए ALSO LACKS EXPLANATION
प्रयागपाद

44

लगता है कि कोई रेगेक्स इस उपयोग के लिए एकदम सही नहीं है। मैं यहाँ एक बहुत ही ठोस पाया

/(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$])/igm

यहाँ पोस्ट किए गए अन्य की तुलना में कुछ अंतर / लाभ:

  • यह ईमेल पतों से मेल नहीं खाता
  • यह लोकलहोस्ट से मेल खाता है: 12345
  • इसके moo.comबिना httpया जैसे कुछ का पता नहीं चलेगाwww

उदाहरण के लिए यहाँ देखें


4
यह www.e से मेल खाता है, यह एक वैध url नहीं है
Ihor Herasymchuk

gविकल्प सभी नियमित अभिव्यक्ति कार्यान्वयन में मान्य नहीं है (रूबी के जैसे अंतर्निहित कार्यान्वयन)।
हुलियक्स

23
text = """The link of this question: /programming/6038061/regular-expression-to-find-urls-within-a-string
Also there are some urls: www.google.com, facebook.com, http://test.com/method?param=wasd
The code below catches all urls in text and returns urls in list."""

urls = re.findall('(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+', text)
print(urls)

आउटपुट:

[
    '/programming/6038061/regular-expression-to-find-urls-within-a-string', 
    'www.google.com', 
    'facebook.com',
    'http://test.com/method?param=wasd'
]

कोटलिन वैल urlRegex = "(?: ?: https?? Ftp): \\ / END /)? [\\ w / \\ -?% =] + \\ [\\ w / \\ -। ; =%।] + "
अक्षय नंदवाना

&यूआरएल में पैरामीटर याद करता है। जैसे कि http://test.com/method?param=wasd&param2=wasd2मिस परम -2
ट्रॉफी गीक

9

यहाँ प्रदान किए गए किसी भी समाधान ने मेरे पास मौजूद समस्याओं / उपयोग-मामलों को हल नहीं किया।

मैंने यहां जो भी प्रदान किया है, वह मुझे अब तक मिला / बनाया गया सर्वश्रेष्ठ है। जब मुझे नए किनारे के मामले मिलेंगे तो मैं इसे अपडेट कर दूंगा।

\b
  #Word cannot begin with special characters
  (?<![@.,%&#-])
  #Protocols are optional, but take them with us if they are present
  (?<protocol>\w{2,10}:\/\/)?
  #Domains have to be of a length of 1 chars or greater
  ((?:\w|\&\#\d{1,5};)[.-]?)+
  #The domain ending has to be between 2 to 15 characters
  (\.([a-z]{2,15})
       #If no domain ending we want a port, only if a protocol is specified
       |(?(protocol)(?:\:\d{1,6})|(?!)))
\b
#Word cannot end with @ (made to catch emails)
(?![@])
#We accept any number of slugs, given we have a char after the slash
(\/)?
#If we have endings like ?=fds include the ending
(?:([\w\d\?\-=#:%@&.;])+(?:\/(?:([\w\d\?\-=#:%@&;.])+))*)?
#The last char cannot be one of these symbols .,?!,- exclude these
(?<![.,?!-])

1
क्या इस जावास्क्रिप्ट को अनुकूल बनाने का कोई तरीका है? जैसा कि नामित कैप्चरिंग समूह वहां पूरी तरह से कार्यात्मक नहीं हैं, इसलिए प्रोटोकॉल मान की जांच मान्य नहीं है।
einord

6

मुझे लगता है कि यह रेगेक्स पैटर्न ठीक वही है जो आप चाहते हैं

/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/

और यह उरल्स निकालने के लिए एक स्निपेट उदाहरण है:

// The Regular Expression filter
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";

// The Text you want to filter for urls
$text = "The text you want  /programming/6038061/regular-expression-to-find-urls-within-a-string to filter goes here.";

// Check if there is a url in the text
preg_match_all($reg_exUrl, $text, $url,$matches);
var_dump($matches);

4

उपरोक्त सभी उत्तर URL में यूनिकोड वर्णों से मेल नहीं खाते, उदाहरण के लिए: http://google.com?query=đức+filan+fã+search

समाधान के लिए, यह काम करना चाहिए:

(ftp:\/\/|www\.|https?:\/\/){1}[a-zA-Z0-9u00a1-\uffff0-]{2,}\.[a-zA-Z0-9u00a1-\uffff0-]{2,}(\S*)

2
URL ( faqs.org/rfcs/rfc1738.html ) पर RFC 1738 के अनुसार यूनिकोड वर्ण वर्जित थे । मानकों के अनुरूप होने के लिए उन्हें प्रतिशत एनकोडेड करना होगा - हालांकि मुझे लगता है कि यह हाल ही में और बदल सकता है - पढ़ने के लायक w3.org/International/articles/idn-and-iri
mrswadge

@mrswadge मैं सिर्फ मामलों को कवर करता हूं। हमें यकीन नहीं है कि सभी लोग मानक के बारे में परवाह करते हैं। आपकी जानकारी के लिए धन्यवाद।
Duc Filan

केवल इसने मेरे लिए पूरी तरह से काम किया जैसे कि " example.com " "www.exmaple.com" " example.com " " example.co.in " " exmaple.com/?q='me '"
कृष

4

यदि आपको लिंक का चयन करने में सख्त होना है, तो मैं इसके लिए जाऊंगा:

(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))

अधिक जानकारी के लिए, इसे पढ़ें:

मिलान URL के लिए एक बेहतर लिबरल, सटीक रेगेक्स पैटर्न


2
ऐसा मत करो। regular-expressions.info/catastrophic.html यह आपके ऐप को मार डालेगा ...
Auric

4

मुझे यह मिला जो उप नमूना भागों सहित अधिकांश नमूना लिंक को कवर करता है।

रेगेक्स है:

(?:(?:https?|ftp):\/\/|\b(?:[a-z\d]+\.))(?:(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))?\))+(?:\((?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))?


2

यदि आपके पास url पैटर्न है, तो आपको अपनी स्ट्रिंग में इसे खोजने में सक्षम होना चाहिए। बस सुनिश्चित करें कि पैटर्न नहीं करता है बनाने ^और $अंकन शुरुआत और यूआरएल स्ट्रिंग के अंत। इसलिए यदि P URL का पैटर्न है, तो P के लिए मिलान देखें।


यह रेगेक्स मैंने पाया है कि सत्यापित करता है कि एक पूरी स्ट्रिंग एक URL है। मैंने भिखारी पर ^ और $ को अंत में निकाल दिया जैसे आपने कहा था और यह अभी भी काम नहीं किया। मैं क्या गलत कर रहा हूं? ^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*[^\.\,\)\(\s]$
user758263

यह मदद कर सकता है यदि आपने दिखाया कि आप किस भाषा का उपयोग कर रहे हैं। किसी भी तरह से, जांच करना सुनिश्चित करें http://regexpal.com/; वहाँ आप अपने स्ट्रिंग के खिलाफ विभिन्न अभिव्यक्तियों का परीक्षण कर सकते हैं जब तक कि आप इसे सही न करें।
प्रवेशिका

@ user758263 - क्या आपको वास्तव में url के लिए इस तरह के एक जटिल रीगेक्स की आवश्यकता है? इस बात पर निर्भर करता है कि आपको वास्तव में क्या संभव हो सकता है। Regex को आज़माने के लिए gskinner.com/RegExr भी देखें । उनके पास Communityटैब के नीचे दाईं ओर सैकड़ों सैंपल भी हैं, जिनमें
उरल्स के

मैं सभी संभावित URL देखने की कोशिश कर रहा हूं और C ++ का उपयोग कर रहा हूं। लिंक एंटोनियो और मनोजों के लिए धन्यवाद। गस्किनर साइट विशेष रूप से सहायक थी क्योंकि इसमें नमूने थे।
user758263

2

मैंने एक स्ट्रिंग में url खोजने के लिए नियमित अभिव्यक्ति के नीचे प्रयोग किया है:

/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/

2
[a-zA-Z]{2,3}TLD से मेल खाने के लिए वास्तव में गरीब है, आधिकारिक सूची देखें: data.iana.org/TLD/tlds-alpha-by-domain.txt
Toto


1

छोटा और सरल। मैंने अभी तक जावास्क्रिप्ट कोड में परीक्षण नहीं किया है लेकिन ऐसा लगता है कि यह काम करेगा:

((http|ftp|https):\/\/)?(([\w.-]*)\.([\w]*))

Regex101.com पर कोड

कोड पूर्वावलोकन


1
मुझे आपका रेगेक्स पसंद आया क्योंकि यह वही था जिसकी मैं तलाश कर रहा था: मुझे कुछ पाठों में से URL को पहचानने और स्ट्रिप करने की आवश्यकता थी, मान्य नहीं। रेलों में काम किया।
डगमार

@ डागमार मुझे यह सुनकर खुशी हुई कि :)
बाफ़सर

1

एक शायद बहुत सरल, लेकिन काम करने का तरीका हो सकता है:

[localhost|http|https|ftp|file]+://[\w\S(\.|:|/)]+

मैंने इसे पायथन पर परीक्षण किया और जब तक स्ट्रिंग पार्सिंग में पहले और बाद में एक जगह है और url में (जिसे मैंने पहले कभी नहीं देखा था) यह ठीक होना चाहिए।

यहां एक ऑनलाइन विचारधारा का प्रदर्शन किया गया है

हालाँकि यहाँ इसका उपयोग करने के कुछ लाभ हैं:

  • यह पहचानता है file:और localhostसाथ ही साथ आईपी पते भी
  • यह उनके बिना कभी मेल नहीं खाएगा
  • यह इस तरह के #या -(इस पोस्ट के यूआरएल देखें) असामान्य पात्रों को बुरा नहीं लगता

1

@JustinLevene द्वारा प्रदान किए गए regex का उपयोग करने से बैक-स्लैश पर उचित एस्केप सीक्वेंस नहीं थे। अब अद्यतित होना सही है, और एफ़टीपी प्रोटोकॉल से मेल खाने के लिए शर्त में जोड़ा गया है: सभी यूआरएल के साथ या प्रोटोकॉल के बिना, और "www।"

कोड: ^((http|ftp|https):\/\/)?([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?

उदाहरण: https://regex101.com/r/uQ9aL4/65


1

सुधार

इस तरह के Urls का पता लगाता है:

regex:

/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/gm

1

खुद को एक लिखा:

let regex = /([\w+]+\:\/\/)?([\w\d-]+\.)*[\w-]+[\.\:]\w+([\/\?\=\&\#]?[\w-]+)*\/?/gm

यह निम्नलिखित सभी डोमेन पर काम करता है:

https://www.facebook.com
https://app-1.number123.com
http://facebook.com
ftp://facebook.com
http://localhost:3000
localhost:3000/
unitedkingdomurl.co.uk
this.is.a.url.com/its/still=going?wow
shop.facebook.org
app.number123.com
app1.number123.com
app-1.numbEr123.com
app.dashes-dash.com
www.facebook.com
facebook.com
fb.com/hello_123
fb.com/hel-lo
fb.com/hello/goodbye
fb.com/hello/goodbye?okay
fb.com/hello/goodbye?okay=alright
Hello www.google.com World http://yahoo.com
https://www.google.com.tr/admin/subPage?qs1=sss1&qs2=sss2&qs3=sss3#Services
https://google.com.tr/test/subPage?qs1=sss1&qs2=sss2&qs3=sss3#Services
http://google.com/test/subPage?qs1=sss1&qs2=sss2&qs3=sss3#Services
ftp://google.com/test/subPage?qs1=sss1&qs2=sss2&qs3=sss3#Services
www.google.com.tr/test/subPage?qs1=sss1&qs2=sss2&qs3=sss3#Services
www.google.com/test/subPage?qs1=sss1&qs2=sss2&qs3=sss3#Services
drive.google.com/test/subPage?qs1=sss1&qs2=sss2&qs3=sss3#Services
https://www.example.pl
http://www.example.com
www.example.pl
example.com
http://blog.example.com
http://www.example.com/product
http://www.example.com/products?id=1&page=2
http://www.example.com#up
http://255.255.255.255
255.255.255.255

आप यह देख सकते हैं कि यह regex101 पर यहां कैसा प्रदर्शन करता है और आवश्यकतानुसार समायोजित करता है


0

यह राजीव के उत्तर के आधार पर / समायोजन पर एक मामूली सुधार है (जो आपको चाहिए)

([\w\-_]+(?:(?:\.|\s*\[dot\]\s*[A-Z\-_]+)+))([A-Z\-\.,@?^=%&amp;:/~\+#]*[A-Z\-\@?^=%&amp;/~\+#]){2,6}?

उदाहरण के लिए यहां देखें कि यह क्या करता है और क्या मेल नहीं खाता।

मुझे "http" आदि के लिए चेक से छुटकारा मिल गया क्योंकि मैं इसके बिना यूआरएल को पकड़ना चाहता था। मैंने कुछ obfuscated url को पकड़ने के लिए regex में थोड़ा जोड़ा (अर्थात "" के बजाय उपयोगकर्ता का उपयोग [डॉट])। अंत में मैंने v2.0 और "moo.0dd" जैसी झूठी सकारात्मकता को कम करने के लिए "AZ" के साथ "\" और "{2,3}" को बदल दिया।

इस स्वागत पर कोई सुधार।


[a-zA-Z]{2,3}TLD के मिलान के लिए वास्तव में खराब है, आधिकारिक सूची देखें: data.iana.org/TLD/tlds-alpha-by-domn.txt । इसके अलावा आपका रेगेक्स _.........&&&&&&यह सुनिश्चित नहीं करता है कि यह एक मान्य यूआरएल है।
टोटो

उस JE SUIS CHAELIE के लिए धन्यवाद, सुधार के लिए कोई सुझाव (विशेष रूप से झूठी सकारात्मक के लिए)?
१०


0
(?:vnc|s3|ssh|scp|sftp|ftp|http|https)\:\/\/[\w\.]+(?:\:?\d{0,5})|(?:mailto|)\:[\w\.]+\@[\w\.]+

यदि आप प्रत्येक भाग का स्पष्टीकरण चाहते हैं, तो regexr में प्रयास करें [।] कॉम जहां आपको हर चरित्र का शानदार विवरण मिलेगा।

यह एक "|" या "OR" क्योंकि सभी उपयोग करने योग्य URI के पास "//" नहीं है, इसलिए यह वह जगह है जहां आप उन योजनाओं की सूची बना सकते हैं, जिनकी आप शर्तों से मेल खाते हैं।


0

मेरे पास c # Uri क्लास का उपयोग है और यह IP एड्रेस, लोकलहोस्ट के साथ काम करता है

 public static bool CheckURLIsValid(string url)
    {
        Uri returnURL;

       return (Uri.TryCreate(url, UriKind.Absolute, out returnURL)
           && (returnURL.Scheme == Uri.UriSchemeHttp || returnURL.Scheme == Uri.UriSchemeHttps));


    }

0

मुझे स्टीफन हेन्ज का समाधान पसंद आया लेकिन यह 34.56 होगा। यह बहुत सामान्य है और मेरे पास अप्रकाशित html है। एक url के लिए 4 एंकर हैं;

www,

http: \ (और सह),

। उसके बाद पत्र और फिर /,

या पत्र। और इनमें से एक: https://ftp.isc.org/www/survey/reports/current/bynum.txt

मैंने इस थ्रेड से बहुत सारी जानकारी का उपयोग किया है। आप सभी को धन्यवाद।

"(((((http|ftp|https|gopher|telnet|file|localhost):\\/\\/)|(www\\.)|(xn--)){1}([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:\\/~+#-]*[\\w@?^=%&\\/~+#-])?)|(([\\w_-]{2,200}(?:(?:\\.[\\w_-]+)*))((\\.[\\w_-]+\\/([\\w.,@?^=%&:\\/~+#-]*[\\w@?^=%&\\/~+#-])?)|(\\.((org|com|net|edu|gov|mil|int|arpa|biz|info|unknown|one|ninja|network|host|coop|tech)|(jp|br|it|cn|mx|ar|nl|pl|ru|tr|tw|za|be|uk|eg|es|fi|pt|th|nz|cz|hu|gr|dk|il|sg|uy|lt|ua|ie|ir|ve|kz|ec|rs|sk|py|bg|hk|eu|ee|md|is|my|lv|gt|pk|ni|by|ae|kr|su|vn|cy|am|ke))))))(?!(((ttp|tp|ttps):\\/\\/)|(ww\\.)|(n--)))"

"Eurls: www.google.com, facebook.com, http: //test.com/" जैसे स्ट्रिंग को छोड़कर हर चीज़ के ऊपर, जो इसे सिंगल स्ट्रिंग के रूप में लौटाता है। Tbh idk क्यों मैंने गोफर आदि को प्रूफ आर कोड जोड़ा

if(T){
  wierdurl<-vector()
  wierdurl[1]<-"https://JP納豆.例.jp/dir1/納豆 "
  wierdurl[2]<-"xn--jp-cd2fp15c.xn--fsq.jp "
  wierdurl[3]<-"http://52.221.161.242/2018/11/23/biofourmis-collab"
  wierdurl[4]<-"https://12000.org/ "
  wierdurl[5]<-"  https://vg-1.com/?page_id=1002 "
  wierdurl[6]<-"https://3dnews.ru/822878"
  wierdurl[7]<-"The link of this question: /programming/6038061/regular-expression-to-find-urls-within-a-string
  Also there are some urls: www.google.com, facebook.com, http://test.com/method?param=wasd
  The code below catches all urls in text and returns urls in list. "
  wierdurl[8]<-"Thelinkofthisquestion:/programming/6038061/regular-expression-to-find-urls-within-a-string
  Alsotherearesomeurls:www.google.com,facebook.com,http://test.com/method?param=wasd
  Thecodebelowcatchesallurlsintextandreturnsurlsinlist. "
  wierdurl[9]<-"Thelinkofthisquestion:/programming/6038061/regular-expression-to-find-urls-within-a-stringAlsotherearesomeurlsZwww.google.com,facebook.com,http://test.com/method?param=wasdThecodebelowcatchesallurlsintextandreturnsurlsinlist."
  wierdurl[10]<-"1facebook.com/1res"
  wierdurl[11]<-"1facebook.com/1res/wat.txt"
  wierdurl[12]<-"www.e "
  wierdurl[13]<-"is this the file.txt i need"
  wierdurl[14]<-"xn--jp-cd2fp15c.xn--fsq.jpinspiredby "
  wierdurl[15]<-"[xn--jp-cd2fp15c.xn--fsq.jp/inspiredby "
  wierdurl[16]<-"xnto--jpto-cd2fp15c.xnto--fsq.jpinspiredby "
  wierdurl[17]<-"fsety--fwdvg-gertu56.ffuoiw--ffwsx.3dinspiredby "
  wierdurl[18]<-"://3dnews.ru/822878 "
  wierdurl[19]<-" http://mywebsite.com/msn.co.uk "
  wierdurl[20]<-" 2.0http://www.abe.hip "
  wierdurl[21]<-"www.abe.hip"
  wierdurl[22]<-"hardware/software/data"
  regexstring<-vector()
  regexstring[2]<-"(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?"
  regexstring[3]<-"/(?:(?:https?|ftp|file):\\/\\/|www\\.|ftp\\.)(?:\\([-A-Z0-9+&@#\\/%=~_|$?!:,.]*\\)|[-A-Z0-9+&@#\\/%=~_|$?!:,.])*(?:\\([-A-Z0-9+&@#\\/%=~_|$?!:,.]*\\)|[A-Z0-9+&@#\\/%=~_|$])/igm"
  regexstring[4]<-"[a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]?"
  regexstring[5]<-"((http|ftp|https)\\:\\/\\/)?([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?"
  regexstring[6]<-"((http|ftp|https):\\/\\/)?([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:\\/~+#-]*[\\w@?^=%&\\/~+#-])?"
  regexstring[7]<-"(http|ftp|https)(:\\/\\/)([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?"
  regexstring[8]<-"(?:(?:https?|ftp|file):\\/\\/|www\\.|ftp\\.)(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[A-Z0-9+&@#/%=~_|$])"
  regexstring[10]<-"((http[s]?|ftp):\\/)?\\/?([^:\\/\\s]+)((\\/\\w+)*\\/)([\\w\\-\\.]+[^#?\\s]+)(.*)?(#[\\w\\-]+)?"
  regexstring[12]<-"http[s:/]+[[:alnum:]./]+"
  regexstring[9]<-"http[s:/]+[[:alnum:]./]+" #in DLpages 230
  regexstring[1]<-"[[:alnum:]-]+?[.][:alnum:]+?(?=[/ :])" #in link_graphs 50
  regexstring[13]<-"^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$"
  regexstring[14]<-"(((((http|ftp|https):\\/\\/)|(www\\.)|(xn--)){1}([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:\\/~+#-]*[\\w@?^=%&\\/~+#-])?)|(([\\w_-]+(?:(?:\\.[\\w_-]+)*))((\\.((org|com|net|edu|gov|mil|int)|(([:alpha:]{2})(?=[, ]))))|([\\/]([\\w.,@?^=%&:\\/~+#-]*[\\w@?^=%&\\/~+#-])?))))(?!(((ttp|tp|ttps):\\/\\/)|(ww\\.)|(n--)))"
  regexstring[15]<-"(((((http|ftp|https|gopher|telnet|file|localhost):\\/\\/)|(www\\.)|(xn--)){1}([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:\\/~+#-]*[\\w@?^=%&\\/~+#-])?)|(([\\w_-]{2,200}(?:(?:\\.[\\w_-]+)*))((\\.[\\w_-]+\\/([\\w.,@?^=%&:\\/~+#-]*[\\w@?^=%&\\/~+#-])?)|(\\.((org|com|net|edu|gov|mil|int|arpa|biz|info|unknown|one|ninja|network|host|coop|tech)|(jp|br|it|cn|mx|ar|nl|pl|ru|tr|tw|za|be|uk|eg|es|fi|pt|th|nz|cz|hu|gr|dk|il|sg|uy|lt|ua|ie|ir|ve|kz|ec|rs|sk|py|bg|hk|eu|ee|md|is|my|lv|gt|pk|ni|by|ae|kr|su|vn|cy|am|ke))))))(?!(((ttp|tp|ttps):\\/\\/)|(ww\\.)|(n--)))"
    }

for(i in wierdurl){#c(7,22)
  for(c in regexstring[c(15)]) {
    print(paste(i,which(regexstring==c)))
    print(str_extract_all(i,c))
  }
}

-1

मैं दो बिंदुओं या अवधियों के बीच पाठ खोजने के तर्क का उपयोग करता हूं

नीचे रेगेक्स अजगर के साथ ठीक काम करता है

(?<=\.)[^}]*(?=\.)



-1

यह सरल है।

इस पैटर्न का उपयोग करें: \b((ftp|https?)://)?([\w-\.]+\.(com|net|org|gov|mil|int|edu|info|me)|(\d+\.\d+\.\d+\.\d+))(:\d+)?(\/[\w-\/]*(\?\w*(=\w+)*[&\w-=]*)*(#[\w-]+)*)?

यह किसी भी लिंक से मेल खाता है:

अनुमत प्रोटोकॉल: http, https और ftp

अनुमत डोमेन: * .com, * .net, * .org, * .gov, * .mil, * .int, * .edu, * .info और * .me OR IP।

अनुमति पोर्ट: सच है

अनुमत पैरामीटर: सच

अनुमति दी गई है: सच है


-2

यह सबसे अच्छा है।

NSString *urlRegex="(http|ftp|https|www|gopher|telnet|file)(://|.)([\\w_-]+(?:(?:\\.[\\w_-]+)‌​+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?";
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.