java8正则表达式匹配非常慢
我有一个regex ^[a-z]+([a-z0-9-]+)*[a-z0-9]+$
用于验证
String src = "alfjaldfjaldmflajdflakclaldkfjaldjlad,fl.adc.aldjfal";
src.matches("^[a-z]+([a-z0-9-]+)*[a-z0-9]+$");
但是,火柴没有回应。 你知道快速正则表达式吗
你可以在下面搜索框中键入要查询的问题!
我有一个regex ^[a-z]+([a-z0-9-]+)*[a-z0-9]+$
用于验证
String src = "alfjaldfjaldmflajdflakclaldkfjaldjlad,fl.adc.aldjfal";
src.matches("^[a-z]+([a-z0-9-]+)*[a-z0-9]+$");
但是,火柴没有回应。 你知道快速正则表达式吗
# 1 楼答案
你的问题在这里:
([a-z0-9-]+)*
您正在尝试匹配一次或多次x0或多次。这没有道理
试试看
([a-z0-9-]+)
或([a-z0-9-]*)
哪一个适合你的需求此外,您还可以使用以下方法编译模式:
这可能会有所帮助,但不是你的问题
# 2 楼答案
只是在详细说明@OldCurmudgeon提供的答案
以微秒为单位的输出
下面的非正则表达式方法只需10微秒