Chirag Dasani
Chirag Dasani

Reputation: 1253

Illegal escape character in grails 2.x

I was developed one application using grails 1.3.7 version. where i was using regex expression for password validation.

like..

 public static final String MYFAX_PASSWORD_REGEX_PATTERN = "[a-zA-Z0-9!@#\$%^&*()<>{};:.\\]\\[]{4,20}"

and it's working fine but when i am upgrading this project into grails 2.x then its' display me below compilation error.

Can anybody help me?

illegal escape character
public static final java.lang.String MYFAX_PASSWORD_REGEX_PATTERN = "[a-zA-Z0-9!@#$%^&*()<>{};:.\]\[]{4,20}";

Upvotes: 0

Views: 419

Answers (2)

Benoit Wickramarachi
Benoit Wickramarachi

Reputation: 6216

You can try the Groovy ~"pattern" expression:

def MYFAX_PASSWORD_REGEX_PATTERN = ~/[a-zA-Z0-9!@#$%^&*()<>{};:.\]\[]{4,20}/

For more information refer to the Groovy Regular Expressions manual.

Upvotes: 1

Daniel Moura
Daniel Moura

Reputation: 7966

The $ is used to put expressions inside a GString. So you should escape it \$

Upvotes: 1

Related Questions