Ad

How To Get All Characters From The Right Up To The Particular Character In Dart

- 1 answer

I am trying to get all characters from the right up to the '*' from below string.

String phoneNumber = '07*** ***253'

Here I want the substring as '253'

ex: '07*** ***4253' result: 4253

Ad

Answer

You can split the string with split()

var _phone = "07*** ***253";

String _last =  _phone.split('*').last;

Or same with regexp

   RegExp reg = RegExp(r'[^*]*$');
    var _matched = reg.allMatches(_phone);

    _matches.last.group(0);
Ad
source: stackoverflow.com
Ad