我正在尝试从字符串中删除模式字符串。[Armor] Reset the Cooldown of Rocket Boots after falling to or below {scale=10|10}% Health.
我知道如何删除模式,但是我需要先删除模式。
在这种情况下,我需要像这样的东西。var pattern = text.getSubstring(new RegExp(r'\{.*?\}'));
是否存在可以使用正则表达式获取子字符串的函数?
最佳答案
不确定您想要什么,但是您可以使用RegExp
实例来匹配字符串,例如:
void main() {
print(RegExp(r'\{.*?\}')
.firstMatch(
'[Armor] Reset the Cooldown of Rocket Boots after falling to or below {scale=10|10}% Health.')
.group(0)); // {scale=10|10}
}
关于dart - dart中有一个函数可以删除带有模式的子字符串吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60094330/