Question:
First time asking a question. So, I’m learning regex and I got this exercise:input string:
:
after CommunicationsException.My solution is:
Answer:
You can matchCause by:
and then match all text up to the next colon, and then start matching from any non-whitespace that is not a colon till the end of string:^
at the start.As an alternative, if you do not care what text is at the string beginning, you can even use
^[^:]+:[^:]+|[^:\s].*
.Details:
^
– start of stringCaused\s+by:
–Caused by:
with any one or more whitespaces betweenCaused
andby
[^:]+
– one or more chars other than:
|
– or[^:\s]
– a char other than whitespace and:
.*
– the rest of the line.
If you have better answer, please add a comment about this, thank you!