0

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?

1
  • 1
    You should be very clear about what you want. What are the delimiters? Is it "bg_img_" and "@s_200" or just "_" and "@"? Can the delimiters occur inside the match? That is: Are you going for a maximal or minimal match in cases where there might be more than one? A RegExp can likely solve the problem in any case (and so can non-RegExp code), but it can only do one thing at a tie, so you should be careful to solve the correct problem. Commented Aug 7, 2020 at 16:57

1 Answer 1

1

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.