每当我尝试匹配正则表达式模式
PREREQasdasdasdasdsadNot+es3adadaK2+0000000+043YEARA_
带
^([a-zA-Z0-9]*|(([a-zA-Z0-9])+(([_]*|[-]|[+])[a-zA-Z0-9]+)*))$
它被绞死
这些可能有帮助的案例很少
•积极案例
asdsadas+asd-asdasdad-asdad+asdasd
UPGRADE+asd-asdasdasdvf-asd
UPGRADE+asd-adsasda__LS-TasdL+asdasdwd
UPGRADE+asd-asdasd__LS-TRI+A+L+asdasdwd
UPG-R-ADE+asd-asd__LS-TRI+A+L+asdasdwd
PREREQ+asdasdasda-Traveler-asd3YEAR+FK20000000043YEAR-A
PREREQ+asdasdd-T_raveler-asdasds3YEAR+FK20000000043YEAR-A
UP_G-R+ADE+asd-ESS__________E+N+T-I_A_LS-TRI+A+L+asdasdwd
PREREQ+asdad-Traveler-asdasd3YEAR+FK200__0-0+0_00043YEAR-A
PREREQasdasdasdTravelerasda3YEARFK20000000043YEARA
UP_G-R+ADE+MTG-ESSENTIA__LS-TRI+A+L+asdasdwd
PREREQasdasdasdasdvfTravelerasdt+esasd2K2+0000000+043YEARA
否定案例
UPG--RADE+asdasd-asdasdasd__LS-TRI+A+L+asdasdwd
UPG-R-ADE_+_asda-asdasdasd__LS-TRI+A+L+asdasdwd
UPG-R-ADE+_asd-asdasdad__LS-TRI+A+L+asdasdwd
UPG-R-ADE+_asd-ESSENTIA__LS-TRI+A+L+asdasdwd
PREREQ+asdasdasdasdvf-asdr-asd++3YEAR+FK20000000043YEAR-A
PREREQ_+-asdasdasdasdvf-asdr-Notes3YEAR+-+FK20000000043YEAR-A
_PREREQ+asdasdasdasdvf-asdr-asd3asdR+FK200__0-0+0_00043YEAR-A
系统挂起(NEG案例)
PREREQ+asdasdasdasdvf-asd-asd3YEAR+-+FK20000000043asdds-A
PREREQasdasdasdasdvfasdrNot+es3YEARFK2+0000000+043asdasd_
答案 0 :(得分:0)
您需要使用\w
^\w+([-+]\w+)*$
\w+
会多次匹配[a-zA-Z\d_]
1次
答案 1 :(得分:0)
已更正(并经过测试)
看着它:
^
(
[a-zA-Z0-9]*
|
(
([a-zA-Z0-9])+
(
([_]*|[-]|[+])
[a-zA-Z0-9]+
)*
)
)
$
可以将其简化为:
^(
[a-zA-Z0-9]+
(
([_]+|[-+])
[a-zA-Z0-9]+
)*
)?$
我还将_*
更正为_+
,否则下划线将适合每个循环场合的每个位置:指数。导致挂起:(_* ...)*
。
^([a-zA-Z0-9]+(([_]+|[-+])[a-zA-Z0-9]+)*)?$
不幸的是,正则表达式在这些事情上失败了,几乎就像停止问题一样。