I have this String Var str:
3002033185160426195531991010-00000000050086093500001 ул. Щевченко 36 а/б 0056763185160426195517991010-00000000080086093500001 ул. Щевченко 36 а/б 0056753185160426195501991010-00000000090086093500001 ул. Щевченко 36 а/б 005674
I need cut string and create new array with values:
array[0] : "3002033185160426195531991010-00000000050086093500001"
array[1] : "0056763185160426195517991010-00000000080086093500001"
array[2] : "0056753185160426195501991010-00000000090086093500001"
I tried to use str.split(" "); but there will be a very large array. How to do it? Help me please!!!
5 Answers 5
This works but its a specific fix for your particular string:
s.split(' ').filter(function(a) {
return a.length > 8;
})
Comments
Assuming that format is fixed:
> arr = str.match(/\d{28}-\d{23}/g)
> ["3002033185160426195531991010-00000000050086093500001", "0056763185160426195517991010-00000000080086093500001", "0056753185160426195501991010-00000000090086093500001"]
Comments
try a string library like stringjs for example. you can use the collapseWhitespace() method to achieve something like this:
var str = S(' String \t libraries are \n\n\t fun\n! ').collapseWhitespace().s; //'String libraries are fun !'
then you can split using the .split(' ') method.
Comments
str.match(/[\d-]{50,}/g)
// => ["3002033185160426195531991010-00000000050086093500001", "0056763185160426195517991010-00000000080086093500001", "0056753185160426195501991010-00000000090086093500001"]
You can tweak the number 50 which should differentiate big numbers you want, like "3002033185160426195531991010-00000000050086093500001", from small numbers you don't, like "36".
Comments
Working example
var str = '3002033185160426195531991010-00000000050086093500001 ул. Щевченко 36 а/б 0056763185160426195517991010-00000000080086093500001 ул. Щевченко 36 а/б 0056753185160426195501991010-00000000090086093500001 ул. Щевченко 36 а/б 005674';
var results = str.match(/[\d-]{50,}/g);
for (i in results) {
var node = document.createElement("LI");
var textnode = document.createTextNode(results[i].toString().trim());
node.appendChild(textnode);
document.getElementById("results").appendChild(node);
}
<ul id="results"></ul>