Reputation: 1011
I'm trying to extract the currency symbol €$ from string using regex. For Example, if my string contains $40.00, I need to get only the $ symbol from the string, Please guide. Example String values: $40.00, 45$,€65,89£.Need to extract any currency.
Upvotes: 0
Views: 593
Reputation: 31219
A tactic is to just remove anything from the String which are not part of the number.
void main() {
print(getCurrencySymbol(r'$40.00')); // $
print(getCurrencySymbol(r'45$')); // $
print(getCurrencySymbol(r'€65,89')); // €
print(getCurrencySymbol(r'100,89 DKK')); // DKK
}
String getCurrencySymbol(String value) =>
value.replaceAll(RegExp(r'[-.,0-9 ]'), '');
Upvotes: 2