How can a KeyListener detect pattern [any string]

I want to detect the pattern instead of any character or keycode stroke is there any way to implement custom key listner which will listen pattern enclosed with [] square braces in vaadin