Regex basic4android-正则表达式与url匹配

Regex basic4android-正则表达式与url匹配,regex,basic4android,Regex,Basic4android,我有以下用于测试url的正则表达式模式,它适用于所有在线正则表达式测试人员,包括b4a的原始正则表达式测试人员(),但不适用于代码 Sub Validate(Url As String)As String Dim Pattern As String=$"^(https:\/\/t\.me\/|https:\/\/telegram\.me\/)[a-z0-9_]{3,15}[a-z0-9]$"$ Dim matcher1 As Matcher matcher1 = Reg

我有以下用于测试url的正则表达式模式,它适用于所有在线正则表达式测试人员,包括b4a的原始正则表达式测试人员(),但不适用于代码

 Sub Validate(Url As String)As String
    Dim Pattern As String=$"^(https:\/\/t\.me\/|https:\/\/telegram\.me\/)[a-z0-9_]{3,15}[a-z0-9]$"$
    Dim matcher1 As Matcher
    matcher1 = Regex.Matcher(Url,Pattern)
    Return matcher1.Find
End Sub
我的网址是

Https://电报。me(+类似于“myChannel”的东西,当然并没有空格,它只是stacks的编辑器,不允许tg链接,所以若你们想选中删除空格)


在所有表单中始终返回false

选项1
使用

选项2
使用

而不是

Dim Pattern As String=$"^(https:\/\/t\.me\/|https:\/\/telegram\.me\/)[a-z0-9_]{3,15}[a-z0-9]$"$
我希望这两种解决方案都是不言自明的

编辑


OP接受了答案后,只做了一点解释。
LineBegin^
LineEnd$
标识符仅在
多行
模式下识别,否则将被忽略。

tnx to@bulbus任何可能面临此问题的人的解决方案是:

 Sub Validate(Url As String)As String
    Dim Pattern As String=$"^(https:\/\/t\.me\/|https:\/\/telegram\.me\/)[a-zA-Z0-9_]{3,15}[a-zA-Z0-9]$"$
    Dim matcher1 As Matcher
    matcher1= Regex.Matcher2(Pattern,Regex.MULTILINE,Url)
    Return matcher1.Find
End Sub

我更改了代码:子验证(Url作为字符串)作为字符串Dim模式作为字符串=$“^(https:\/\/t\.me\/| https:\/\/telegram\.me\/)[a-zA-Z0-9\{3,15}[a-zA-Z0-9]$”$Dim matcher1作为匹配器matcher1=Regex.Matcher(Url,模式)Return matcher1.Find End Sub在https://telegram.me/meysamac这样的url上仍然不起作用。您还可以使用
RegexOptions。多行
使用我在回答中使用IgnoreCase的多行选项。我希望它抛出一个错误,而不是返回
False
:-)
Dim Pattern As String=$"^(https:\/\/t\.me\/|https:\/\/telegram\.me\/)[a-z0-9_]{3,15}[a-z0-9]$"$
 Sub Validate(Url As String)As String
    Dim Pattern As String=$"^(https:\/\/t\.me\/|https:\/\/telegram\.me\/)[a-zA-Z0-9_]{3,15}[a-zA-Z0-9]$"$
    Dim matcher1 As Matcher
    matcher1= Regex.Matcher2(Pattern,Regex.MULTILINE,Url)
    Return matcher1.Find
End Sub