1

每当我尝试匹配正则表达式模式时

    PREREQasdasdasdasdsadNot+es3adadaK2+0000000+043YEARA_

    ^([a-zA-Z0-9]*|(([a-zA-Z0-9])+(([_]*|[-]|[+])[a-zA-Z0-9]+)*))$

它被绞死了

这些是少数可能有帮助的案例

• 阳性病例

  1. asdsadas+asd-asdasdad-asdad+asdasd
  2. UPGRADE+asd-asdasdasdvf-asd
  3. UPGRADE+asd-adsasda__LS-TasdL+asdasdwd
  4. UPGRADE+asd-asdasd__LS-TRI+A+L+asdasdwd
  5. UPG-R-ADE+asd-asd__LS-TRI+A+L+asdasdwd
  6. PREREQ+asdasdasda-Traveler-asd3YEAR+FK20000000043YEAR-A
  7. PREREQ+asdasdd-T_raveler-asdasds3YEAR+FK20000000043YEAR-A
  8. UP_G-R+ADE+asd-ESS__________E+N+T-I_A_LS-TRI+A+L+asdasdwd
  9. PREREQ+asdad-Traveler-asdasd3YEAR+FK200__0-0+0_00043YEAR-A
  10. PREREQasdasdasdTravelerasda3YEARFK20000000043YEARA
  11. UP_G-R+ADE+MTG-ESSENTIA__LS-TRI+A+L+asdasdwd
  12. PREREQasdasdasdasdvfTravelerasdt+esasd2K2+0000000+043YEARA

负面案例

  1. UPG--RADE+asdasd-asdasdasd__LS-TRI+A+L+asdasdwd
  2. UPG-R-ADE_+_asda-asdasdasd__LS-TRI+A+L+asdasdwd
  3. UPG-R-ADE+_asd-asdasdad__LS-TRI+A+L+asdasdwd
  4. UPG-R-ADE+_asd-ESSENTIA__LS-TRI+A+L+asdasdwd
  5. PREREQ+asdasdasdasdvf-asdr-asd++3YEAR+FK20000000043YEAR-A
  6. PREREQ_+-asdasdasdasdvf-asdr-Notes3YEAR+-+FK20000000043YEAR-A
  7. _PREREQ+asdasdasdasdvf-asdr-asd3asdR+FK200__0-0+0_00043YEAR-A

系统挂起(NEG 案例)

  1. PREREQ+asdasdasdasdvf-asd-asd3YEAR+-+FK20000000043asdds-A
  2. PREREQasdasdasdasdvfasdrNot+es3YEARFK2+0000000+043asdasd_
4

2 回答 2

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]+)*)?$

不幸的是,正则表达式在这些事情上失败了,几乎就像停止问题一样。

于 2013-06-06T07:16:48.170 回答
0

你需要使用\w

^\w+([-+]\w+)*$

\w+将匹配[a-zA-Z\d_]1 到多次

于 2013-06-06T07:08:49.687 回答