【发布时间】:2018-09-20 07:13:06
【问题描述】:
在 Flutter 应用程序中,我需要检查字符串是否与特定的 RegEx 匹配。但是,我从应用程序的 JavaScript 版本复制的 RegEx always 在 Flutter 应用程序中返回 false。我在regexr 上验证了 RegEx 是有效的,并且这个 RegEx 已经在 JavaScript 应用程序中使用,所以它应该是正确的。
感谢任何帮助!
正则表达式:/^WS{1,2}:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:56789/i
测试代码:
RegExp regExp = new RegExp(
r"/^WS{1,2}:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:56789/i",
caseSensitive: false,
multiLine: false,
);
print("allMatches : "+regExp.allMatches("WS://127.0.0.1:56789").toString());
print("firstMatch : "+regExp.firstMatch("WS://127.0.0.1:56789").toString());
print("hasMatch : "+regExp.hasMatch("WS://127.0.0.1:56789").toString());
print("stringMatch : "+regExp.stringMatch("WS://127.0.0.1:56789").toString());
输出:
allMatches : ()
firstMatch : null
hasMatch : false
stringMatch : null
【问题讨论】: