0

I got this

'','','{12345678},{87654321}','lk12l1k2l12lkl12lkl121l2lk12'

trying to match it using '(.*?)',|'(.*?)'

It successfully got my 4 chunks

''
''
'{12345678},{87654321}'
'lk12l1k2l12lkl12lkl121l2lk12'

But I am trying to use the same regex in split... it doesn't like it. :(

var str = "'','','{12345678},{87654321}','lk12l1k2l12lkl12lkl121l2lk12'";
str.split(/'(.*?)',|'(.*?)'/);

Any idea...? ugh.

2
  • 1
    What does "doesn't like it" mean? Commented Mar 31, 2014 at 15:52
  • It splitted incorrectly, instead of 4, is getting 12, basically it considering ' as 1, also , as 1 as well. Commented Mar 31, 2014 at 15:59

2 Answers 2

1

Why are you using split?

You can get your four chunks with match:

var chunks = str.match(/'[^']*'/g);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you master, is it possible to remove the single quotes using the match at the same time?
For IE > 8: str.match(/'[^']*'/g).map(function(v) { return v.slice(1, -1)})
0

Is the split() neccessary?

You could always get the information between the quotes using match().

test.match(/'(.*?)'/g)

Test it please.

2 Comments

Nope, tried something similar before I post, your solution messes up with the inner comma.
I changed my answer. Please check it out and let me know.

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.