Hi guy's I am new to the regex and i am trying the create the expression for the pattern of the string value the rules are as below 

```
1) String must start with the 'O' or 'T'
2) After that there must be 9 digits 
3) After that there must be 'T'
4) After that alphanumeric string with specs and numbers and character'D' these can repeat any number of time in string of length 25 
5) Then character 'O'
6) Then string with numbers and spaces of length 5  

```

However i am done with the all the conditions but for the condition **4** i am not sure how to do it because it can repeat 'D' any number of times in given string with length 25. Write now i have adjusted the optional 'D' at every place where it present in the string that is kind of very lengthy regex so I was hoping some one would help me with condition **4** .Any help would be great.

The string to match -->

```
T011600062TO51D45D0399D0O 1807

```

The latest regex -->

```
(?x)((?:[OT]\d{9})(?:T\s*\d*\s*[0-9DO ]\d*\s*[OD0-9 ]\s*\d*[D0-9]\s*\d*[0-9OD ]\d*)(?:[O]\s*\d*)\b)

```

I am confused about this part of regex 

```
(?:T\s*\d*\s*[0-9DO ]\d*\s*[OD0-9 ]\s*\d*[D0-9]\s*\d*[0-9OD ]\d*)

```

is this the correct way ?