Can you tell me the regex for capturing class name from below line:
[2011-09-14 20:43:31:943 GMT][E08C17F94E8.http-8080-Processor21]com.abc.MyClass] INFO login successful
Here, I need to capture MyClass.
So far, I was able to capture entire com.abc.MyClass using (?i)^(?:[^\[]*\[){3}
But I couldn’t capture MyClass.
Any help is much appreciated.
Thanks!
If you can assume there are never brackets after that last one, it is pretty simple:
This captures all of the alphanumeric characters directly preceding the last
]in the string.Note: you don’t need to do
[^\]]because the spec for PCRE says if the]is the first in the character list, you don’t need to escape it.EDIT: Since you cannot assume no brackets, here is another one that will work:
This throws away the first two sets of brackets, and grabs the largest chunk of alphanumeric characters before the next bracket. The
?in.+?makes it a non-greedy multiplier, so it will match as few characters as possible, which makes this regex very simple and efficient.Nothing against daxnitro, but that regex makes me want to give up programming.