regex - 使用正则表达式 Dart/Flutter 提取数据
问题描述
我想从以下内容中提取数据
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
检查到目前为止我尝试过的 示例
解决方案
You may use
Sv-loon\s*([\s\S]*?)\s*Datum:
See the regex demo. Details:
Sv-loon
- a literal string\s*
- 0 or more whitespaces([\s\S]*?)
- Group 1: any 0 or more chars as few as possible\s*
- 0 or more whitespacesDatum:
- a literal string
See Dart demo:
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));
}
Output
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
推荐阅读
- azure-devops - vsts - 限制访问以创建“史诗”和“功能”级别的项目
- nested - 奥里利亚。为什么我的嵌套 repeat.for 选择不显示数据?
- mysql - Eclipselink:临时表的列长度和 mb4
- docker - SSL - 将受信任的根证书安装到 aspnetcore docker 容器
- xcode10 - Xcode10.0 (10A255) import intent xx.h 出现错误
- java - 在将一个文件的内容复制到另一个文件时,“'”正在转换为“’”
- vhdl - 为什么我会得到这个“4 个可能的定义”VHDL 连接错误
- angular - 在订阅方法中成功添加到数据库后,Angular 6 和 Angular 材质对话框未打开
- python - SQLAlchemy 查询数据库并显示为 html 表单
- android - Android Room - 关系和 LiveData