I wrote a piece of code where am able to replaced a string with something else using replaceAll and replaceAllMapped
//this is to replace a number
String cutNumber(String text) => text.replaceAllMapped(RegExp(r'(^(?:[+0]9)?[0-9]{11,}$)'),
(Match m) => "<Not Allowed>");
//this is to replace an email address first method
String cutText(String text) => text.replaceAllMapped(
RegExp(
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$',
),
(Match m) => "<Not Allowed>");
//this is to replace an email address second method
String cutText(String text) => text.replaceAll(
RegExp(
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$',
),
"<Not Alloed>");
This usually works if is the single in this format
String email = "example@gmail.com";
String number = "089462453746";
String bothString = "example@gmail.com and 089462453746";
print cutNumber(number); //prints out <Not Allowed>
print cutText(email); // both first and second method prints out <Not Allowed>
print cutNumber(cutText(bothString)); // now this doesn't even replace anything, just prints out example@gmail.com and 089462453746
for email it outputs <Not Allowed> same with the number but for the bothString it doesn't change anything at all it just prints out example@gmail.com and 089462453746 instead of <Not Allowed> and <Not Allowed>. Please is there any place am doing something wrong. I want it to replace it even if there are more words in the string