My code isvar String = "e-commerce software|mobile"
And I want to split this string into e-commerce
software
mobile
with only one split sentence. I am not very familiar with regex.
Thank you for your help.
My code isvar String = "e-commerce software|mobile"
And I want to split this string into e-commerce
software
mobile
with only one split sentence. I am not very familiar with regex.
Thank you for your help.
var String = "e-commerce software|mobile";
console.log(String.split(/[\s]|[\|]/));
As you know, you can split by one separator doing this:
String.split('|');
To do the same thing using a regular expression, you could type this:
String.split(/\|/);
With regular expressions, you can combine single possible expressions using []
. So to split on either a space or |
you could do this:
String.split(/[ |\|]/);