【发布时间】:2022-11-18 22:55:54
【问题描述】:
我无法为特定规则创建正则表达式。
主要规则:
[FIX -A or -D or -P with numbers and several times is possible uppercase string] : string
我的测试:
[FIX-A2569] TOTO : toto // should passed
[FIX-D256458-P4565] TOTO : toto // should passed
[FIX-D123123-A123123-A123123-P123123] TOTO : toto // should passed
[FIX-D123123-A123123-P123123] TOTO : toto // should passed
[FIX-D123123-A123123-A123123-P123123] TOTO : toto // should passed
[FIX-D123123-A123123A123123-P123123] TOTO : toto // should not passed
[FIX-D123123A123123A123123P123123] TOTO : toto // should not passed
[FIX-D123123-A123123A123123P123123] TOTO : toto // should not passed
我的正则表达式:
/\[FIX-A[0-9]+|-D[0-9]+|-P[0-9]+\] [A-Z0-9 _]+ : .+/g
我的结果:
什么都没过去。
【问题讨论】:
-
不要使用
g标志,正则表达式可以如下所示,或^\[FIX(?:-[ADP]\d+)+] [A-Z0-9_]+ : .+
标签: regex