0

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!!!

asked Apr 26, 2016 at 15:44

5 Answers 5

1

This works but its a specific fix for your particular string:

s.split(' ').filter(function(a) {
 return a.length > 8;
})

Working example

answered Apr 26, 2016 at 15:48
Sign up to request clarification or add additional context in comments.

Comments

1

Assuming that format is fixed:

> arr = str.match(/\d{28}-\d{23}/g)
> ["3002033185160426195531991010-00000000050086093500001", "0056763185160426195517991010-00000000080086093500001", "0056753185160426195501991010-00000000090086093500001"]
answered Apr 26, 2016 at 15:49

Comments

1

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.

answered Apr 26, 2016 at 15:50

Comments

1
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".

answered Apr 26, 2016 at 15:50

Comments

1

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>

answered Apr 26, 2016 at 16:05

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.