split with regex is not returning correct repsonse [duplicate]











up vote
-2
down vote

favorite













This question already has an answer here:




  • My regex is matching too much. How do I make it stop?

    5 answers



  • Regular expression to stop at first match

    6 answers



  • Regex to first occurence only?

    4 answers




I have a string



var str3 = "[a,b,c] there [s,b,c] how are u";


What i want is [there, how are u] but I am getting ["", "how are u"], when splitting with str3.split(/[.*]/);



Any idea how i shud do it?










share|improve this question













marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 8:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • its because your regex matches entire section [a,b,c] there [s,b,c] instead of just [a,b,c]
    – y2k-shubham
    Nov 20 at 8:45












  • Your [.*] pattern matches [a,b,c] there [s,b,c] and thus remove this substring and puts an empty string and the rest of the string into an array. Use a non-greedy (also called "lazy") quantifier, *?, instead of *. You may remove empty matches by adding .filter(Boolean) to the split result. Also, to split with whitespace, too, at the same time, use .split(/[.*?]|s+/).filter(Boolean).
    – Wiktor Stribiżew
    Nov 20 at 8:53

















up vote
-2
down vote

favorite













This question already has an answer here:




  • My regex is matching too much. How do I make it stop?

    5 answers



  • Regular expression to stop at first match

    6 answers



  • Regex to first occurence only?

    4 answers




I have a string



var str3 = "[a,b,c] there [s,b,c] how are u";


What i want is [there, how are u] but I am getting ["", "how are u"], when splitting with str3.split(/[.*]/);



Any idea how i shud do it?










share|improve this question













marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 8:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • its because your regex matches entire section [a,b,c] there [s,b,c] instead of just [a,b,c]
    – y2k-shubham
    Nov 20 at 8:45












  • Your [.*] pattern matches [a,b,c] there [s,b,c] and thus remove this substring and puts an empty string and the rest of the string into an array. Use a non-greedy (also called "lazy") quantifier, *?, instead of *. You may remove empty matches by adding .filter(Boolean) to the split result. Also, to split with whitespace, too, at the same time, use .split(/[.*?]|s+/).filter(Boolean).
    – Wiktor Stribiżew
    Nov 20 at 8:53















up vote
-2
down vote

favorite









up vote
-2
down vote

favorite












This question already has an answer here:




  • My regex is matching too much. How do I make it stop?

    5 answers



  • Regular expression to stop at first match

    6 answers



  • Regex to first occurence only?

    4 answers




I have a string



var str3 = "[a,b,c] there [s,b,c] how are u";


What i want is [there, how are u] but I am getting ["", "how are u"], when splitting with str3.split(/[.*]/);



Any idea how i shud do it?










share|improve this question














This question already has an answer here:




  • My regex is matching too much. How do I make it stop?

    5 answers



  • Regular expression to stop at first match

    6 answers



  • Regex to first occurence only?

    4 answers




I have a string



var str3 = "[a,b,c] there [s,b,c] how are u";


What i want is [there, how are u] but I am getting ["", "how are u"], when splitting with str3.split(/[.*]/);



Any idea how i shud do it?





This question already has an answer here:




  • My regex is matching too much. How do I make it stop?

    5 answers



  • Regular expression to stop at first match

    6 answers



  • Regex to first occurence only?

    4 answers








javascript regex






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 8:42









Raaz

727929




727929




marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 8:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 8:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • its because your regex matches entire section [a,b,c] there [s,b,c] instead of just [a,b,c]
    – y2k-shubham
    Nov 20 at 8:45












  • Your [.*] pattern matches [a,b,c] there [s,b,c] and thus remove this substring and puts an empty string and the rest of the string into an array. Use a non-greedy (also called "lazy") quantifier, *?, instead of *. You may remove empty matches by adding .filter(Boolean) to the split result. Also, to split with whitespace, too, at the same time, use .split(/[.*?]|s+/).filter(Boolean).
    – Wiktor Stribiżew
    Nov 20 at 8:53




















  • its because your regex matches entire section [a,b,c] there [s,b,c] instead of just [a,b,c]
    – y2k-shubham
    Nov 20 at 8:45












  • Your [.*] pattern matches [a,b,c] there [s,b,c] and thus remove this substring and puts an empty string and the rest of the string into an array. Use a non-greedy (also called "lazy") quantifier, *?, instead of *. You may remove empty matches by adding .filter(Boolean) to the split result. Also, to split with whitespace, too, at the same time, use .split(/[.*?]|s+/).filter(Boolean).
    – Wiktor Stribiżew
    Nov 20 at 8:53


















its because your regex matches entire section [a,b,c] there [s,b,c] instead of just [a,b,c]
– y2k-shubham
Nov 20 at 8:45






its because your regex matches entire section [a,b,c] there [s,b,c] instead of just [a,b,c]
– y2k-shubham
Nov 20 at 8:45














Your [.*] pattern matches [a,b,c] there [s,b,c] and thus remove this substring and puts an empty string and the rest of the string into an array. Use a non-greedy (also called "lazy") quantifier, *?, instead of *. You may remove empty matches by adding .filter(Boolean) to the split result. Also, to split with whitespace, too, at the same time, use .split(/[.*?]|s+/).filter(Boolean).
– Wiktor Stribiżew
Nov 20 at 8:53






Your [.*] pattern matches [a,b,c] there [s,b,c] and thus remove this substring and puts an empty string and the rest of the string into an array. Use a non-greedy (also called "lazy") quantifier, *?, instead of *. You may remove empty matches by adding .filter(Boolean) to the split result. Also, to split with whitespace, too, at the same time, use .split(/[.*?]|s+/).filter(Boolean).
– Wiktor Stribiżew
Nov 20 at 8:53














1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










You shouldn't be greedy:



str3.split(/[.*?]s*/);


:-)






share|improve this answer























  • do point me to the duplicate, I will close this @WiktorStribiżew
    – Raaz
    Nov 20 at 8:46






  • 1




    Sorry, didn't know it's a duplicate... What do you suggest to do with duplicates?
    – MarcoS
    Nov 20 at 8:46










  • Should I better delete my answer?
    – MarcoS
    Nov 20 at 8:52












  • You cannot delete accepted answers. Once the question is eligible for removal I will cast a delete vote.
    – Wiktor Stribiżew
    Nov 20 at 9:45




















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










You shouldn't be greedy:



str3.split(/[.*?]s*/);


:-)






share|improve this answer























  • do point me to the duplicate, I will close this @WiktorStribiżew
    – Raaz
    Nov 20 at 8:46






  • 1




    Sorry, didn't know it's a duplicate... What do you suggest to do with duplicates?
    – MarcoS
    Nov 20 at 8:46










  • Should I better delete my answer?
    – MarcoS
    Nov 20 at 8:52












  • You cannot delete accepted answers. Once the question is eligible for removal I will cast a delete vote.
    – Wiktor Stribiżew
    Nov 20 at 9:45

















up vote
0
down vote



accepted










You shouldn't be greedy:



str3.split(/[.*?]s*/);


:-)






share|improve this answer























  • do point me to the duplicate, I will close this @WiktorStribiżew
    – Raaz
    Nov 20 at 8:46






  • 1




    Sorry, didn't know it's a duplicate... What do you suggest to do with duplicates?
    – MarcoS
    Nov 20 at 8:46










  • Should I better delete my answer?
    – MarcoS
    Nov 20 at 8:52












  • You cannot delete accepted answers. Once the question is eligible for removal I will cast a delete vote.
    – Wiktor Stribiżew
    Nov 20 at 9:45















up vote
0
down vote



accepted







up vote
0
down vote



accepted






You shouldn't be greedy:



str3.split(/[.*?]s*/);


:-)






share|improve this answer














You shouldn't be greedy:



str3.split(/[.*?]s*/);


:-)







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 at 8:45

























answered Nov 20 at 8:44









MarcoS

8,9051663130




8,9051663130












  • do point me to the duplicate, I will close this @WiktorStribiżew
    – Raaz
    Nov 20 at 8:46






  • 1




    Sorry, didn't know it's a duplicate... What do you suggest to do with duplicates?
    – MarcoS
    Nov 20 at 8:46










  • Should I better delete my answer?
    – MarcoS
    Nov 20 at 8:52












  • You cannot delete accepted answers. Once the question is eligible for removal I will cast a delete vote.
    – Wiktor Stribiżew
    Nov 20 at 9:45




















  • do point me to the duplicate, I will close this @WiktorStribiżew
    – Raaz
    Nov 20 at 8:46






  • 1




    Sorry, didn't know it's a duplicate... What do you suggest to do with duplicates?
    – MarcoS
    Nov 20 at 8:46










  • Should I better delete my answer?
    – MarcoS
    Nov 20 at 8:52












  • You cannot delete accepted answers. Once the question is eligible for removal I will cast a delete vote.
    – Wiktor Stribiżew
    Nov 20 at 9:45


















do point me to the duplicate, I will close this @WiktorStribiżew
– Raaz
Nov 20 at 8:46




do point me to the duplicate, I will close this @WiktorStribiżew
– Raaz
Nov 20 at 8:46




1




1




Sorry, didn't know it's a duplicate... What do you suggest to do with duplicates?
– MarcoS
Nov 20 at 8:46




Sorry, didn't know it's a duplicate... What do you suggest to do with duplicates?
– MarcoS
Nov 20 at 8:46












Should I better delete my answer?
– MarcoS
Nov 20 at 8:52






Should I better delete my answer?
– MarcoS
Nov 20 at 8:52














You cannot delete accepted answers. Once the question is eligible for removal I will cast a delete vote.
– Wiktor Stribiżew
Nov 20 at 9:45






You cannot delete accepted answers. Once the question is eligible for removal I will cast a delete vote.
– Wiktor Stribiżew
Nov 20 at 9:45





Popular posts from this blog

Tonle Sap (See)

I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

Guatemaltekische Davis-Cup-Mannschaft