-4

My current input...

var str = "3.   1203    Copra 4.   1204          Linseed, whether      or      not broken. 5.   1205          Rape    or colza seeds, whether or not broken. 6.   1206         Sunflower seeds, whether or not broken. "

what I need output is

[ 1203    Copra, 204  Linseed, whether      or      not broken., 1205          Rape    or colza seeds, whether or not broken., .... etc]

As simple as I need to split the string where I find number with dot.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Vishal
  • 11
  • 1
  • 5
  • 1
    Possible duplicate of [How to split and modify a string in NodeJS?](https://stackoverflow.com/questions/15134199/how-to-split-and-modify-a-string-in-nodejs) – Abhi Jun 30 '17 at 15:45

4 Answers4

3

You can handle it with String#match.

const str = "1.one 2. two 3.three",
      res = str.match(/(?!\d\.\s?)\w+/g);
      
      console.log(res);
kind user
  • 40,029
  • 7
  • 67
  • 77
2

You could use a regular expression with takes only a group of letters.

var string = "1.one 2. two 3.three";
    array = string.match(/[a-z]+/g)
    
console.log(array);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392
2

To match the items of a numbered list in a string and return an array try this:

var x = "1. Buy bananas 2. Buy a tent  3. Book flight to jungle  4. Eat banana in jungle and 5. come up with better sample for regex"
var result = x.match(/(?!\d\.\s)(\w+\D+)/gm);
console.log(result)
Johannes
  • 316
  • 3
  • 4
0

For your current string - just match the words containing letters:

var str = "1.one 2. two 3.three",
    result = str.match(/[^0-9. ]+/g);
    
console.log(result);
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105