flutter
flutter

Reputation: 6766

Get a substring using 2 patterns in Dart?

How can I pull out a string from two different patterns either side of the string I want: eg

 String s=  bg_img_pulloutthisstring@s_200

How can I pull out pulloutthisstring from s?

Upvotes: 0

Views: 97

Answers (1)

julemand101
julemand101

Reputation: 31209

The easiest is to use a Regular Expression and use a match group:

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

Upvotes: 1

Related Questions