tonymx227
tonymx227

Reputation: 5451

Regex with or and specific chars

I'm not able to create a regex for a specific rule.

The main rule :

[FIX   -A or -D or -P with numbers and several times is possible     uppercase string]      :     string

My tests :

[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

My REGEX :

/\[FIX-A[0-9]+|-D[0-9]+|-P[0-9]+\] [A-Z0-9 _]+ : .+/g

My result :

Nothing passed.

Upvotes: 1

Views: 40

Answers (1)

boppy
boppy

Reputation: 1908

Just keep your regex short and use a tool to design it from left to right. This way you'll see when the expression gets stuck.

I would suggest /\[FIX(-[ADP]\d+)+] [A-Z0-9]+ : .*/ as the regex:

https://regexr.com/72nd9

Use Regexr's explain-function to learn more about the regex.

Upvotes: 1

Related Questions