Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Dart中使用2个图案获得子字符串?_Dart - Fatal编程技术网

在Dart中使用2个图案获得子字符串?

在Dart中使用2个图案获得子字符串?,dart,Dart,我怎样才能从两种不同的图案中拉出一根我想要的线的任一侧:例如 String s= bg_img_pulloutthisstring@s_200 如何从s中拉出此字符串?最简单的方法是使用正则表达式和匹配组: void main() { const s = 'bg_img_pulloutthisstring@s_200'; print(RegExp(r'bg_img_(.*)@s_200').firstMatch(s).group(1)); // pulloutthisstring

我怎样才能从两种不同的图案中拉出一根我想要的线的任一侧:例如

 String s=  bg_img_pulloutthisstring@s_200

如何从s中拉出此字符串?

最简单的方法是使用正则表达式和匹配组:

void main() {
  const s = 'bg_img_pulloutthisstring@s_200';
  print(RegExp(r'bg_img_(.*)@s_200').firstMatch(s).group(1)); // pulloutthisstring
}
你应该非常清楚你想要什么。分隔符是什么?它是“bg_img_”和“@s_200”还是仅仅是“_”和“@”?分隔符可以出现在匹配中吗?也就是说:在可能存在多个匹配的情况下,您是要进行最大匹配还是最小匹配?在任何情况下,
RegExp
都可能解决问题(非RegExp代码也是如此),但它一次只能做一件事,因此您应该小心地解决正确的问题。