SugiuraY
SugiuraY

Reputation: 361

How to extract before "@" on email adress

I'd like to extraxt string "test", which is the letters before "@",by using RegExp like following, but actually could get "test@" including "@". How can I get only "test" without "@" ?

final getPass = "[email protected]";
final regEx = RegExp(r'(.+?)@');
print(regEx.firstMatch(getPass)?.group(0));

Upvotes: 0

Views: 534

Answers (2)

Augustin R
Augustin R

Reputation: 7819

If using a Regexp is not mandatory for you, you could use String methods :

final getPass = "[email protected]";
print(getPass.split("@").first);

Upvotes: 2

Ritik Banger
Ritik Banger

Reputation: 2748

Use .group(1)

final getPass = "[email protected]";
final regEx = RegExp(r'(.+?)@');
print(regEx.firstMatch(getPass)?.group(1));

Upvotes: 0

Related Questions