我想从一个字符串中提取数字(整数,小数或12:30格式)。 我使用了以下正则表达式,但没有成功:
final RegExp numberExp = new RegExp(
"[a-zA-Z ]*\\d+.*",
caseSensitive: false,
multiLine: false
);
final RegExp numberExp = new RegExp(
"/[+-]?\d+(?:\.\d+)?/g",
caseSensitive: false,
multiLine: false
);
String result = value.trim();
result = numberExp.stringMatch (result);
result = result.replaceAll("[^0-9]", "");
result = result.replaceAll("[^a-zA-Z]", "");
到目前为止,没有什么是完美的。
感谢任何帮助。
\s
)。你可能需要类似于r'.*?(\d*).*'
或r'[^0-9]*([0-9]*).*'
的东西。我没有测试这些示例,而且我不经常使用正则表达式,所以要小心。(仅在我的手机上) - Günter Zöchbauer