Flutter/Dart:How to extract email and phone number from a string in Flutter

Viewed 1664

How do I extract phone and email information from a description field in flutter

here is an example text

 Good to know you!<br/><br/> <br/>Apply online today! 
    If you have any questions please contact fname@lname@company.com<br/>theUser will reach out if we believe you would be a good fit.<br/><br/>
<br>111-222-3333</br>

I would like to get the phone#(111-222-3333) and email(fname@lname@company.com)

Thanks for your help

3 Answers
final mailPattern = r"\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b";
final regEx = RegExp(mailPattern, multiLine: true);
final obtainedMail = regEx.allMatches(text.toString()).map((m) => m.group(0)).join(' ');

Use this code as a reference.

text is a list which i converted into a long string by writing text.toString()

Try this for phone numbers starting with +country code detection in a multiline string.

\b[+]*[(]{0,1}[6-9]{1,4}[)]{0,1}[-\s\.0-9]*\b
Related