i am trying to pass variable in regex language DART
`betweenLenth(val, field, [min = 4, max = 20]) {
final RegExp nameExp = new RegExp(r'^\w{" + min + "," + max + "}$');
if (!nameExp.hasMatch(val))
return field + " must be between $min - $max characters ";
}`
thanks
You can't use string-interpolation with raw strings.
With interpolation
final RegExp nameExp = new RegExp('^\\w{"$min","$max"}\$');
final RegExp nameExp = new RegExp('^\\w{$min,$max}\$');
with concatenation
final RegExp nameExp = new RegExp(r'^\w{"' + min + '","' + max + r'"}$');
final RegExp nameExp = new RegExp(r'^\w{' + min + ',' + max + r'}$');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With