mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix regex
This commit is contained in:
parent
d75ddf8e2c
commit
179cd2c8ba
@ -103,11 +103,12 @@ public interface RegexPool {
|
|||||||
/**
|
/**
|
||||||
* URL
|
* URL
|
||||||
*/
|
*/
|
||||||
String URL = "[a-zA-z]+://[^\\s]*";
|
String URL = "[a-zA-Z]+://[\\w-+&@#/%?=~_|!:,.;]*[\\w-+&@#/%=~_|]";
|
||||||
/**
|
/**
|
||||||
* Http URL
|
* Http URL(来自:http://urlregex.com/)<br>
|
||||||
|
* 此正则同时支持FTP、File等协议的URL
|
||||||
*/
|
*/
|
||||||
String URL_HTTP = "(https://|http://)?([\\w-]+\\.)+[\\w-]+(:\\d+)*(/[\\w- ./?%&=:]*)?";
|
String URL_HTTP = "(https?|ftp|file)://[\\w-+&@#/%?=~_|!:,.;]*[\\w-+&@#/%=~_|]";
|
||||||
/**
|
/**
|
||||||
* 中文字、英文字母、数字和下划线
|
* 中文字、英文字母、数字和下划线
|
||||||
*/
|
*/
|
||||||
|
@ -230,7 +230,10 @@ public class ValidatorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isUrlTest(){
|
public void isUrlTest(){
|
||||||
String content = "https://detail.tmall.com/item.htm?id=639428931841&ali_refid=a3_430582_1006:1152464078:N:Sk5vwkMVsn5O6DcnvicELrFucL21A32m:0af8611e23c1d07697e";
|
String content = "https://detail.tmall.com/item.htm?" +
|
||||||
System.out.println(Validator.isMatchRegex(Validator.URL_HTTP, content));
|
"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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user