I'm looking to match any string that contains a [DEBUG] statement and that eventually will have a :  string following it. If there are several :  strings following it, I want to match the first. The idea is to then color both the [DEBUG] statement and what's next to the first : .An example would be:  [thread1] [DEBUG] [2017.03.12 23:22:12] com.abc.def.Xyz: some log message: some more specific info.should be translated into:  [thread1] ${RED}[DEBUG]${DEFAULT} [2017.03.12 23:22:12] com.abc.def.Xyz: ${RED}some log message.${DEFAULT}For that, I thought the following sed replace string would suffice, but it doesn't:sed -r s/(\[DEBUG\])([^:]*: )(.*)$/${RED}\1${DEFAULT}\2${RED}\3{$DEFAULT}/I've lost hours around this but unfortunately it doesn't match the shown above string. Any clues on why?
sed string not matching. Why?
sed
You are trying to match, for group 2, anything except a : up to a :, but there are colons in the time, so you don't match.  You can try replacing the [^:] with . and likely get the same results, unless you have a : somewhere else in the line, then it will match up until the last occurrence of that string.Perhaps a better pattern, though, issed -r 's/(\[DEBUG])( \[[[:digit:].: ]*] [^:]*: )(.*)/${RED}\1${DEFAULT}\2${RED}\3${DEFAULT}/'