gpt4 book ai didi

dart - 在Dart中使用2种模式获取子字符串?

转载 作者:行者123 更新时间:2023-12-03 04:40:43 25 4
gpt4 key购买 nike

如何从想要的字符串的任一侧的两个不同模式中提取字符串:例如

 String s=  bg_img_pulloutthisstring@s_200
如何从s中拉出 pulloutthisstring

最佳答案

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

void main() {
const s = 'bg_img_pulloutthisstring@s_200';
print(RegExp(r'bg_img_(.*)@s_200').firstMatch(s).group(1)); // pulloutthisstring
}

关于dart - 在Dart中使用2种模式获取子字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63301002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com