(?x) # flag to enable regex comments
(?<= # begin positive lookbehind
^ # start of line
// # literal forwardslashes (may need escaping as \/\/ in some languages)
) # end positive lookbehind
[^/]++ # match any non-/ and keep matching possessively until a / or end of string found.
# not sure .NET supports the possessive quantifier (++) - a greedy (+) is good enough here.
6条答案
按热度按时间w8rqjzmb1#
Uri
:3duebb1j2#
只是另一个选项,为了显示不同的选项:
服务器名称将是
\0
或$0
,或者仅仅是函数的结果,这取决于您如何调用它以及您的语言提供的内容。regex注解模式下的解释:
mec1mxoz3#
这个应该可以了
服务器名称位于第一个捕获组中
s4n0splo4#
匹配
servername
的正则表达式:wlp8pajw5#
很丑,但它只是工作:
aij0ehis6#
使用System.Uri主机属性:https://learn.microsoft.com/en-us/dotnet/api/system.uri.host?view=net-7.0