[英]basic4android - regex match with url
我有以下用于测试网址的正则表达式模式,它可以与所有在线正则表达式测试器(包括b4a原始正则表达式测试器( https://b4x.com:51041/regex_ws/index.html ))一起正常工作,但不能在代码中使用!
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://电报。 我(+类似'myChannel'的东西,没有空格,它只是堆栈的编辑器,不允许tg链接,因此如果您要检查删除空格,则可以)
总是以各种形式返回false
tnx到@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
选项1
采用
matcher1 = Regex.Matcher(Url,Pattern,RegexOptions.IgnoreCase)
选项2
采用
Dim Pattern As String=$"^(https:\/\/t\.me\/|https:\/\/telegram\.me\/)[a-zA-Z0-9_]{3,15}[a-zA-Z0-9]$"$
代替
Dim Pattern As String=$"^(https:\/\/t\.me\/|https:\/\/telegram\.me\/)[a-z0-9_]{3,15}[a-z0-9]$"$
我希望这两种解决方案都是自我解释!
编辑
OP接受了答案后,仅作一点解释。 仅在MULTILINE
模式下才能识别LineBegin ^
和LineEnd $
标识符,否则将忽略它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.