Ad
How To Get Delimiters After Split By Multiple Delimiters?
I use this phones = value.split(RegExp(r":| |:| |)"));
to split my phone numbers, so I got 内線
, 7+90+21931465
and 070-2193-1465
from 内線:7+90+21931465:070-2193-1465
, but I want to show them as 内線:7+90+21931465:070-2193-1465, how can I get array as 内線
, :
, 7+90+21931465
, :
and 070-2193-1465
?
Ad
Answer
var value = '内線:7+90+21931465:070-2193-1465';
var regExp = RegExp(r'^(.+)(:|:)(.+)(:|:)(.+)$');
print(value);
var match = regExp.firstMatch(value);
var numGroups = match.groupCount;
var groups = match.groups(List<int>.generate(numGroups, (i) => i + 1));
print(groups.toString());
Another way:
var chesu = value.split(RegExp(r':|:'))..insert(1, ':')..insert(3, ':');
print(chesu);
Ad
source: stackoverflow.com
Related Questions
- → How to replace *( in a string
- → Regex extract string after the second "." dot character at the end of a string
- → CodeMirror regex doesn't match behavior typical Javascript regex parser
- → JS Get multiple links in a string
- → Using capture group $1 to access object's key value
- → Difference between /(a|b)/ and /[ab]/ in JavaScript split() using regex
- → In Nginx, how to match and entire URL and Query String and redirect to a URL and Query String
- → Reorder lines in a string based on first two numbers inside
- → How to manage URL with or without ? and /
- → Not sure why this Regex is returning true
- → Laravel extract excerpt from content using tinymce
- → Cannot get my multiple regex working for specific case in URL structure
- → laravel5.1 validate number
Ad