Home > Net >  Flutter regexp for version
Flutter regexp for version

Time:06-08

I need regexp for version input. It can be any amount of numbers separated by a dot.

Here are some valid variants

1.2.3.4.5
1
111.123.23
12.23

Currently, I have this variant

FilteringTextInputFormatter.allow(RegExp(r'^[\d,.] '))

but it allows multiple dots in a line. So 123....3 works for it, and it is not correct.

CodePudding user response:

You can use

^(?:\d \.)*\d $
  • ^ Start of a string
  • (?: Non-capturing group
    • \d \. Match any digit that and a dot after it
  • ) Close non-capturing group
  • * The previous match zero or more times
  • \d Finally must match any digit without a dot next to it
  • $ End of a string

See the demo

CodePudding user response:

Found a solution, So as dart regex is more of JS - I used JS regex tester and got this as solution : RegExp(r'[\d] .?')

  • Related