Vinicius Morais
Vinicius Morais

Reputation: 595

Is there a function in dart to remove substring with pattern?

I'm trying to remove a pattern string from a string.

[Armor] Reset the Cooldown of Rocket Boots after falling to or below {scale=10|10}% Health.

I know how to remove the pattern, but i need to get the pattern before remove it.

In this case i need something like these.

var pattern = text.getSubstring(new RegExp(r'\{.*?\}'));

Is there a function that can get a substring with regex?

Upvotes: 0

Views: 38

Answers (1)

julemand101
julemand101

Reputation: 31209

Not entirely sure what you want but you can use an instance of RegExp to match against a String like:

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}
}

Upvotes: 1

Related Questions