LoginSignup
9
4

More than 3 years have passed since last update.

[Dart] 正規表現を使って文字列を分割して List にする

Last updated at Posted at 2019-09-22

例えば、 f5f6f7f8 みたいなのを アルファベット一文字 と 数字一文字 をセットとした List にしたい時。
こう書く。 See: https://api.dartlang.org/stable/2.5.0/dart-core/RegExp-class.html

void main() {
  String str = "F5f6F7f8abcdefg";
  print(_splitMoves(str)); // => [F5, f6, F7, f8]
}

List<String> _splitMoves(String moves) {
  final exp = RegExp(r'([a-hA-H]{1}[1-8]{1})');
  return exp?.allMatches(moves).map((match) => match.group(0)).toList();
}
9
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4