How to overcome the error related to Regex pattern for password check?


#1

I have Regex pattern “^(?=.[a-z])(?=.[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$”.
I am facing the error Illegal escape \d. Do we have any alternative to this in kotlin?


#2

Have you tried \\d?


#3
"""^(?=.[a-z])(?=.[A-Z])(?=.*\d)[a-zA-Z\d]{8,}""" + '$'

#4

You don’t need to separate $, it’ll work just fine in this pattern.


#5

Regex("^[\\w]{8,}$")