Refactored regex caning mechanism and case sensitivity handling