Katalon cannot detect Unicode char "\" in regex ^[\p{L}0-9.@_\-&()+=\<>?#/]*$

Please help me on this

Thanks

1 Like

Hi there,

I will make it as a public message so everyone from our community can support you!

In a Double-Quoted String in Java and Groovy, a single backslash character is used to form a special sequence. For example

"\n"

stands for a newline character.

"\t"

stands for a tab character, and so on. However, in Groovy, a string "\p" is not defined as a type of special character like newline and tab. That is the reason why you got an error.


In Groovy you can use Single-Quote String instead of Double-Quote string:

Pattern.compile('\p{Lower}')

In a Single-Quote String, a backslash character \ is regarded as a plain single character, not the start of special character. See Types of Strings in Groovy | Baeldung for Types of Strings in Groovy.


Or, in a Double-Quote string, you can espace a backslash using a backslash character prepended.

Pattern.compile("\\p{Lower}")

You should read the “Backslashes, escapes, and quoting” in the Javadoc of java.util.regex.Pattern

3 Likes

Thanks, Kazurayam. It’s working normally.

1 Like