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

1

4 Answers 4

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);

Sign up to request clarification or add additional context in comments.

1 Comment

I did not get the input according to my input string if
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);

Comments

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)

Comments

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);

Comments

Your Answer

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.