[Solved] Regular Expression specific to a particular message pattern with mandatory elements


This will do it for you:

^[\w.]+=\$\d+(?:\|[\w.]+=\$\d+)*$

It matches at least one word character or . followed by an =, $ and a digit. Then, optionally, a | followed by the first sequence again. This optional part can be repeated any number of times.

See it here at regex101.

Edit

Allow multi-digit numbers.

Edit 2

If you need to check the range being 0-12 use

^[\w.]+=\$(?:\d|1[012])(?:\|[\w.]+=\$(?:\d|1[012]))*$

Here’s an example.

Edit 3

As OP needed pure POSIX, here’s what we ended up with:

^[A-Za-z0-9_.]+=\$(1[012]|[0-9])(\|[A-Za-z0-9_.]+=\$(1[012]|‌​[0-9]))*$

No shorthand character classes nor non capturing groups.

7

solved Regular Expression specific to a particular message pattern with mandatory elements