Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
URL 可以是以下之一:
http://spappsdev.domain.com/sites/sitename/ http://spappsdev/sites/sitename/
我想以一种适用于两个 URL 的方式提取“spappsdev”。这甚至可能吗?我讨厌不得不运行两个正则表达式命令。
尝试使用环顾四周:
^https?://\K[^/\.]+
或者 :
(?<=://)[^/\.]+
在 shell 中使用perl的一个真实示例:
$ perl -lne 'm!(?<=://)[^/\.]+! and print $&' file spappsdev spappsdev
要将结果分配给 shell 变量:
$ var="$(perl -lne 'm!(?<=://)[^/\.]+! and print $&' file)" $ echo "$var"
您可以使用:
\bhttps?:\/\/([^\/.]+)
并抓住匹配组#1