regex - 使用正则表达式Dart/Flutter提取数据

标签 regex flutter dart

我想从以下提取数据

Periode Aantal uur Sv-loon
01-06-2019 t/m 30-06-2019 35 € 800,00
01-05-2019 t/m 31-05-2019 35 € 1.056,00
01-04-2019 t/m 30-04-2019 35 € 800,00
01-03-2019 t/m 31-03-2019 35 € 800,00
01-02-2019 t/m 28-02-2019 35 € 800,00
Datum: 06 augustus 2019
预期的输出是:
01-06-2019 t/m 30-06-2019 35 € 800,00
01-05-2019 t/m 31-05-2019 35 € 1.056,00
01-04-2019 t/m 30-04-2019 35 € 800,00
01-03-2019 t/m 31-03-2019 35 € 800,00
01-02-2019 t/m 28-02-2019 35 € 800,00
检查到目前为止我尝试了什么example

最佳答案

您可以使用

Sv-loon\s*([\s\S]*?)\s*Datum:
参见regex demo详细信息:
  • Sv-loon-文字字符串
  • \s*-0个或多个空格
  • ([\s\S]*?)-组1:尽可能少的0个或更多字符
  • \s*-0个或多个空格
  • Datum:-文字字符串

  • 参见Dart演示:
    String txt = "Periode Aantal uur Sv-loon\n01-06-2019 t/m 30-06-2019 35 € 800,00\n01-05-2019 t/m 31-05-2019 35 € 1.056,00\n01-04-2019 t/m 30-04-2019 35 € 800,00\n01-03-2019 t/m 31-03-2019 35 € 800,00\n01-02-2019 t/m 28-02-2019 35 € 800,00\nDatum: 06 augustus 2019";
     RegExp rx = RegExp(r'Sv-loon\s*([\s\S]*?)\s*Datum:');
     Match match = rx.firstMatch(txt);
     if (match != null) {
         print(match.group(1));
     }
    
    输出量
    01-06-2019 t/m 30-06-2019 35 € 800,00
    01-05-2019 t/m 31-05-2019 35 € 1.056,00
    01-04-2019 t/m 30-04-2019 35 € 800,00
    01-03-2019 t/m 31-03-2019 35 € 800,00
    01-02-2019 t/m 28-02-2019 35 € 800,00
    

    关于regex - 使用正则表达式Dart/Flutter提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63342690/

    相关文章:

    regex - grep - 正则表达式 - 匹配到一个特定的词

    javascript - 如何使用正则表达式提取正文内容

    flutter - 如何在 flutter 中动态隐藏和显示底栏

    android - flutter : How to prevent rebuild of whole Reorderable Listview?

    java - 如何在 Java 中删除字符串中的重复字符并修剪字符串中的空格?

    java - 如何在java中将camelCase字符串转换为下划线,保留一些大写,其余的小写?

    firebase - Flutter:在框架模块 'firebase_core.FLTFirebasePlugin' 中包含非模块化头文件

    当类用作值而不是字符串时, flutter 下拉失败

    flutter - 如何在 flutter 中获取设备的总内存大小?

    Flutter:如何使用 HapticFeedback