I'm trying to split a string into parts of length 4 in Dart/Flutter.
The best way to do this is by using a regular expression if I'm not wrong. Based on my regex knowledge and digging around I've settled on this regex /.{1,4}(?=(.{4})+(?!.))|.{1,4}$/g
. However, I can't figure out how to use it in dart
Here's what I have so far.
String cardNum = "4444444444444444";
List<String> cardNums=cardNum.split(
RegExp(r".{1,4}(?=(.{4})+(?!.))|.{1,4}$"));
I've already tested regexr
I expect cardNums
to be ["4444","4444","4444","4444"]
Instead I'm getting [, , , , ]