我有下面的regex模式来测试一个url,它可以很好地与所有在线regex测试人员一起工作,包括b4a的原始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://电报。me (+像'myChannel‘这样没有诅咒空格的东西,它只是栈的编辑器,不允许tg链接,所以如果你想检查删除空格)
总是在所有表单上返回false
发布于 2017-09-22 23:35:13
选项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接受了答案之后,只做了一点解释。LineBegin ^和LineEnd $标识符只有在MULTILINE模式下才能识别,否则将被忽略。
发布于 2017-09-23 08:35:12
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 Subhttps://stackoverflow.com/questions/46374253
复制相似问题