Is there a way to detect long running regex in Pattern/Matcher class other than timing match call? A way to check how many times a character match is done will be preferred solution. Calling code could get an exception at set number of calls. As of now it is not possible to extend Pattern class and override match methods of its inner final classes.