简体   繁体   中英

how to add ', [] regex special characters in flutter

I've making signup form screen

I made Regex patterns

    Pattern pattern =
        r'^(?=.*[a-zA-Z])(?=.*[*".!@#$%^&(){}:;<>,.?/~_+-=])(?=.*[0-9]).{8,30}$';

problem is if i add ', [ ] it doesn't work.

if I add ' error occurs in Android studio ( \ escape doesn't work ) 在此处输入图像描述

if I add [, ], \, =, | these character, error doesn't occurs in AS but validation doesn't work in AVD and console says

The following FormatException was thrown while handling a gesture:
Unterminated character class^(?=.*[*.!@#$%^&(){}:;<>,?/~_+-=\]).{8,30}$

How can I fix this??

You should be able to solve this by concatenating your regex

Pattern pattern = r'^(?=.*[a-zA-Z])(?=.*[*".!@#\$%^&(){}:;<>,.\' + r"'?/~_+-=])(?=.*[0-9]).{8,30}\$";

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