Password Polices not working

I want to add Password Polices on Keycloak by using a java code.

When I am trying to set “Not Recently Used, Password Blacklist, Expire Password, Regex” polices then an error occurs.Other polices are set on Keycloak and working fine, but I got the error on these polices.

Example: 1
RealmResource realmResource = keycloak.realm(“realmName”);RealmRepresentation realmRepresentation = new RealmRepresentation();realmRepresentation.setPasswordPolicy(“length(8) and maxLength(9) and notUsername() and notEmail() and digits(1) and lowerCase(1) and upperCase(1) and specialChars(1)”);realmResource.update(realmRepresentation); (Working)

Example: 2
RealmResource realmResource = keycloak.realm(“realmName”);
RealmRepresentation realmRepresentation = new RealmRepresentation();realmRepresentation.setPasswordPolicy(" regex((?=.\d)(?=.[a-z])(?=.[A-Z])(?=.[@#$%^&+=]).{8,})“) and expirePassword(200) and notRecentlyUsed(3) and passwordBlacklist(test)”);realmResource.update(realmRepresentation); (Not Working Example)

Any solution?

Thank you!