(? < = / / |) (\ w) +\.) +\ w+) (\: (\ d +)) how to understand this rule

(? < = / / |) (w) +.) + w +) (: (d +)) how to understand this rule
Mar.31,2021

this regular wants to match the URL, similar to this one (with domain name and port number) http://second.www.baidu.com:8080 and second.www.baidu.com:8080 , take the part after or after the beginning of / / . There is something wrong with the regular writing of
. The intention of / / should be changed to \ /\ / after adding escape characters, and the intention of (\ w) + should be written as \ w + .

rewrote (? < =\ /\ / | ^) ((\ w +\.) (\: (\ d +))

explain in segments:

  1. (? < =\ /\ / ^) requires that the matching target must be preceded by / / or the matching target must be at the front.
  2. (\ w +\.) +\ w + match text. one or more + text, such as abcd.efgh abcd.efgh.izk abcd.efgh.izk.sfds can be matched, abcd cannot be matched alone
  3. \: (\ d+) match : multiple digits , that is, port number
Menu