EN
TypeScript - split string using regex
0
points
In this short article, we would like to show how to split some strings using a regular expression as a separator in TypeScript.
Quick solution:
const phoneNumber: string = '+48 888-444-000';
const separator: RegExp = /[ -]+/;
const parts: string[] = phoneNumber.split(separator);
console.log(parts);
Output:
['+48', '888', '444', '000']
Where: /[ -]+/ means multiple spaces, dashes, or mix of them.