In a string, I need all timecodes to be formatted as following [HH:MM:SS] or [HH:MM:SS.ms]. Some of them are already in brackets. They can be everywhere, beginning, middle, or end of a phrase.
I'd like to put those not in brackets in brackets.
To select all of them I use:
[\[]?\d\d:\d\d:\d\d(.\d+)?[\]]?
I tried
(?!\[.+\])(.|^)(\d\d:\d\d:\d\d(.\d+)?)(.|$)(?!\[.+\])
Which is almost fine except that my selection $2 includes space characters in the case of string not beggining by ^ or finishing by $.
How can I get rid of this selection?