1

I want to split a string :

OU(EGAL([Zone_libre_utilisateur],"0000"),ET([Code_courrier],"ABO"))

using delimeter , & ( in javascript. How can it be done?

2
  • What output do you expect for this example? Commented Jul 7, 2010 at 10:05
  • @galambalazs Looking at the string, I believe he meant to split only at , and ( Commented Jul 7, 2010 at 10:11

3 Answers 3

6

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", ""]
Sign up to request clarification or add additional context in comments.

Comments

1
var splitString = originalString.split(/[,(]/);

Comments

0

I would replace all the ( characters with , and then use the split method...

e.g. something like...

string.replace('(',',').split(',')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.