Splitting a string in JavaScript by multiple delimeters
I want to split a string :
OU(EGAL([Zone_libre_utilisateur],"0000"),ET([Code_courrier],"ABO"))
using delimeter ,
& (
in ja开发者_如何学Pythonvascript. How can it be done?
You can use a regex to split:
var str = 'OU(EGAL([Zone_libre_utilisateur],"0000"),ET([Code_courrier],"ABO"))';
var a = str.split(/[,(]/);
console.log(a);
//["OU", "EGAL", "[Zone_libre_utilisateur]", ""0000")", "ET", "[Code_courrier]", ""ABO"))"]
Or even better (depending on your requirement):
var str = 'OU(EGAL([Zone_libre_utilisateur],"0000"),ET([Code_courrier],"ABO"))';
var a = str.split(/[,()[\]"]+/);
console.log(a);
//["OU", "EGAL", "Zone_libre_utilisateur", "0000", "ET", "Code_courrier", "ABO", ""]
var splitString = originalString.split(/[,(]/);
I would replace all the ( characters with , and then use the split method...
e.g. something like...
string.replace('(',',').split(',')
精彩评论