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
CodePudding user response:
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
}