I am newbie in regex world, I need to capture some different types of strings.
By the way please suggest more elagant way to capture such strings. n = any positive n
You could validate the line first, then just findall with \d+
Validate: '~^\|[1-9]\d*\|(?:\|(?:[1-9]\d*|0+(?!\|\|[1-9]))\|){4}$~'
^ # BOS
\|
[1-9] \d* # Any numbers that start with non-zero
\|
(?:
\|
(?:
[1-9] \d* # Any numbers that start with non-zero
| # or,
0+ # Any numbers with all zeros
(?! \|\| [1-9] ) # Not followed by a non-zero
)
\|
){4}
$ # EOS