简体   繁体   中英

Substitution of Unicode character classes in javascript regex

I have a regex for validating a password in my javascript app , which is as follows :

/^(?=.*[az])(?=.*[AZ])(?=.*\\d)(?=.*[!@#$^.*()_])[a-zA-Z\\d!@#$^.*()_]{8,64}$/gm

This essentially accepts passwords containing at least one uppercase letter , one lowercase letter , one number and a special char , along with a length between 8 and 64 characters .

I wish to re-write it in Java using the Unicode classes provided here.

How do I go translating this JS regex to its java equivalent ?

PS : A translation of a js regex for a weak password is provided here for reference

JS Regex without unicode classeS :

/^(?=.*[az])(?=.*[AZ])(?=.*\\d)[a-zA-Z\\d!@#$^.*()_]{8,64}$/gm

Regex translated with Unicode classes :

^(?=.*\\\\p{Ll})(?=.*\\\\p{Lu})(?=.*\\\\p{N})[\\\\p{L}\\\\p{N}]*

这应该工作

^(?=.*\\p{Ll})(?=.*\\p{Lu})(?=.*\\p{N})(?:(?=.*\\p{P})|((?=.*\\p{S})))[\\p{L}\\p{N}\\p{P}\\p{S}]{8,64}$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM