Reputation: 2667
I am trying to keep the tail end of the split
myLink = link.split(/\d/, 2)[1]
However the string it is splitting
link = 1 some text 800 hello world
would get split like:
1,
some text
I end up losing the tail end 800 hello world
.
What can I do to keep this information.
Upvotes: 1
Views: 248
Reputation: 831
var link = '1 some text 800 hello world';
var myLink = link.match(/[A-Z\s]?[a-z\s]+|[0-9]+/g);
alert(myLink);
This will definitely lead you for what you want.
Upvotes: 1
Reputation: 831
var link = "1 some text 800 hello world";
var myLink = link.split(/\d+/,[0-9]);
alert(myLink[1]); //this will give you some text
alert(myLink[2]); //this will give you hello world
Upvotes: 0
Reputation: 12018
This is because you are passing a limit of 2 to the split function so you are only getting two results in your split array. Omit the 2 and you'll get them all:
var splitArray = link.split(/\d/);
Upvotes: 1