all! I have this text: "Some text from uri http://test.com and other words.". And I need to get uri parts using one regex.
I try this:
string text = "Some text with uri http://test.com and other words."; string pattern = @"\b(\S+)://([^:]+)(?::(\S+))?\b"; MatchCollection matches = Regex.Matches(text, pattern);
And it works when I write "Some text with uri http://test.com " or "word1 http://test.com/10000 word2".
Where is the mistake?
Your second modifier +is greedy, so it matches everything after http://if it doesn't fall at :or at the end of the line. Try the following:
+
http://
:
@"\b(\w+)://([^:]+?)(?::(\S+))?\b"
... , ...
, , ...
\b(\S+)://([^: ]+)
Source: https://habr.com/ru/post/1791623/More articles:php debugging POST vars - posthttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1791619/when-does-it-matter-to-use-d-over-s-when-formatting-integers-to-strings-in-python&usg=ALkJrhhhOIBU1p3KQrBwHtMmxAuNb2IDaQRadical use of the admin interface - pythonScalable UDP Server - c ++Double loop - controlsSecure connection in Android - androidHow do you get the segmented control value in flipside mode to calculate Mainview? updated - iosiPhone app connecting from FLipSideView to MainView? - iphoneКак заполнить "дыры" в нерегулярной разнесенной сетке или массиве с отсутствующими данными? - statisticsCustom Property Animation in CALayer - calayerAll Articles