fix regex

This commit is contained in:
Looly 2021-11-04 01:16:05 +08:00
parent d75ddf8e2c
commit 179cd2c8ba
2 changed files with 9 additions and 5 deletions

View File

@ -103,11 +103,12 @@ public interface RegexPool {
/**
* URL
*/
String URL = "[a-zA-z]+://[^\\s]*";
String URL = "[a-zA-Z]+://[\\w-+&@#/%?=~_|!:,.;]*[\\w-+&@#/%=~_|]";
/**
* Http URL
* Http URL来自http://urlregex.com/<br>
* 此正则同时支持FTPFile等协议的URL
*/
String URL_HTTP = "(https://|http://)?([\\w-]+\\.)+[\\w-]+(:\\d+)*(/[\\w- ./?%&=:]*)?";
String URL_HTTP = "(https?|ftp|file)://[\\w-+&@#/%?=~_|!:,.;]*[\\w-+&@#/%=~_|]";
/**
* 中文字英文字母数字和下划线
*/

View File

@ -230,7 +230,10 @@ public class ValidatorTest {
@Test
public void isUrlTest(){
String content = "https://detail.tmall.com/item.htm?id=639428931841&ali_refid=a3_430582_1006:1152464078:N:Sk5vwkMVsn5O6DcnvicELrFucL21A32m:0af8611e23c1d07697e";
System.out.println(Validator.isMatchRegex(Validator.URL_HTTP, content));
String content = "https://detail.tmall.com/item.htm?" +
"id=639428931841&ali_refid=a3_430582_1006:1152464078:N:Sk5vwkMVsn5O6DcnvicELrFucL21A32m:0af8611e23c1d07697e";
Assert.assertTrue(Validator.isMatchRegex(Validator.URL, content));
Assert.assertTrue(Validator.isMatchRegex(Validator.URL_HTTP, content));
}
}