0

How can i outputs result between 2 specific characters in dart String

example

    String myVlue = 'helloWorld';
    wanted result is : anything between 'hel' and 'ld'
    so the result is 'loWor'

Note : in my case the two specific characters are fixed and Unique

How can i tell dart to do that in best way .

thanks

1 Answer 1

2

You could define a regular expression to catch a group from your input:

void main() {
  String myValue = 'helloWorld';
  RegExp regExp = RegExp(r'hel(.*)ld');
  String extract = regExp.firstMatch(myValue)![1]!;
  print(extract); // loWor
}
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.