Monday, 15 July 2013

javascript - Split using two delimiters -


How divided by using two delimiters is my code below where I am using string (). How to divide both by using () and {(in the string below).

  var str = 'abc xyz () ab {(}) pp' var res = Str.split ("()"); Console.log (res); // ['abc xyz', 'ab {(}) pp']  

I have tried to do something that is not properly divided

 res = str.split (/ [\}) \ () /] /  

I expect something below

  [' Abc xyz ',' ab ','}) pp ']  

If str =' abc xyz () ab {(}) pp bb yy {(KK Lowe ' , I want the output to be ['abc xyz', 'ab', '}') PP bb yy {(kk llop '] . The partition should only be on the first instance.

  var str = 'abc xyz () ab {(}) pp 'Var result = str.split (/ (?: \ (\) | \ {\ () /); Warning (JSON.stringify (result));  

Something like this:

  str.split (/ (?: \ (\) | \ {\ () /)  

You can use either | to match either () or {(. ?: It does non-capturing.


No comments:

Post a Comment