countLetters method
To count the occurrences of the letters sequence in a text and check for consecutive occurrences of target letters Here's
an Example:
==================================================================>
String longText = "This is an example text with ab letters and ab words. It also contains abbreviations like abc and abcd. The rabbit jumped over the ab fence.";
int count = longText.countLetters("ab");
print("The sequence 'ab' appears $count times in the text.");
==================================================================>
Implementation
int countLetters(String target) {
final RegExp targetRegExp = RegExp(target);
return targetRegExp.allMatches(this).length;
}