Your RegEx is fine, rather it could be simplified (perhaps optimized) as below:
(?x)
(
(?:T\d{9})
(?:T\s*\d{0,19}\s*[0-9DO ]\d{0,19}\s*[OD0-9 ]\s*\d{0,19}\s*\d{0,19}[0-9D ]\d{0,19})
(?:O\s*\d{0,19})
\b
)
One thing I have found in your RegEx, is unnecessary use of (...)
. Moreover, using \s{0,19}
or \s{0,5}
could be simply written as \s*
. The last one is better, only if you're not restricted to use of 0-19
times or 0-5
times.