Regular expression to retrieve part of a URL

Today I am lazy and do not want to understand this. I need a regular expression to match "jeremy.miller" and "scottgu" from the following inputs:

http://codebetter.com/blogs/jeremy.miller/archive/2009/08/26/talking-about-storyteller-and-executable-requirements-on-elegant-code.aspx

http://weblogs.asp.net/scottgu/archive/2009/08/25/clean-web-config-files-vs-2010-and-net-4-0-series.aspx

Ideas?

Edit

Chris Lutz did an excellent job with the requirements outlined above. What if it was input, so you could not use the β€œarchive” in the regular expression?

 http://codebetter.com/blogs/jeremy.miller/
 http://weblogs.asp.net/scottgu/
+3
source share
2 answers

Will this be what you are looking for?

'/([^/]+)/archive/'

"" . /, . , archive, lookahead, lookaheads, ( ), , lookahead , archive, .

EDIT: , , , . , , / , :

'/([^/]+)/$'

jeremy.miller, scottgu, , URL-, "" URL- (.. scottgu2), /:

'/(jeremy\.miller|scottgu)/'

, , "", , /:

'http://[^/]+/(?:blogs/)?([^/]+)/'

, blogs, . (?:) - , , , , , , - , . (?:) . , , Perl, , PCRE. - , , .

. . .

+7

:

/\/([\w\.]+)\/archive/
+5

Source: https://habr.com/ru/post/1716173/


All Articles