Q:

how use regexp in flutter?

I want this format.see at photo.
I use this code 
RegExp(r'^(?=.*[0-9])(?=\\S+$).{8,40}$').hasMatch(text).

This code is ok for java but not for dart.I don't know why?

A:

My guess is that double-backslashing might be unnecessary, and:
^(?=.*[0-9])(?=\S+$).{8,40}$

might simply work.

Maybe, you might want to a bit strengthen/secure the pass criteria, maybe with some expression similar to:
(?=.*[0-9])(?=.*[A-Za-z])(?=.*[~!?@#$%^&*_-])[A-Za-z0-9~!?@#$%^&*_-]{8,40}$

which allows,

a minimum of one digit,
a minimum of one upper/lower case, and
at least one of these chars: ~!?@#$%^&*_-

If you wish to simplify/modify/explore the expression, it's been explained on the top right panel of regex101.com. If you'd like, you can also watch in this link, how it would match against some sample inputs.

Reference

Dart >> dart:core >> RegExp abstract class

Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters

How to use RegEx in Dart?

