Hi! I have a webpage (HTML) and an textbox where I write data. The strings looks like this "0000020300024000500000000200908111024211 Hi how are you" I just want the first 8 digits without zeros in the beginning. example: 00030500001 => 30560 12345678000024 => 12345678 I want to strip the "00000" and the digits after 203 so the script alerts: 203 Hi how are you I want the script to look like this in the end -> "alert (number +<br /> +text1 +<br /> +text2 +<br /> +text3 +<br /> +text4); The problem: * I can just replace the zeros in front of 203, but not the other digits. * I can't put the text in variabel "text1-4" * It can't handle multilines, just the first line. Output: "203 Hi how are you" - it only takes the first line, "Hi how are you" is still there and ignores the second line.... I want it to look like this: "203" "204" The script looks like this: function split() { var output = document.getElementById("textfield").value; var result = output.replace(/^[0]+/g,""); alert("result"); }
Hi, if I understood correctly you could do it like: var str = "0000020300024000500000000200908111024211 Hi how are you"; var num = str.substr(0,8).replace(/^[0]+/g, ''); var txt = str.replace(/[0-9]+/g, '').split(' '); alert(num + txt.join('<br />')); Is it what you needed?