0

How can I extract words (which can be anything) out of a string which are separated by non-alphabetic characters (digits or symbols) and save the result in an array.

For example if I parsed the following I would like to have the name of the three fruits in an array.

var input str = '= ((1 * bananas ^ 5) - oranges / mangos)'  // to get [bananas, oranges, mangos]

The practical application of this is that, I would like to extract variable names from a mathematical formula, after which I can assign values to them (which I'd get from some object or array)

Crocodile
  • 5,724
  • 11
  • 41
  • 67

1 Answers1

1

You can match [a-z]+:

'= ((1 * bananas ^ 5) - oranges / mangos)'.match(/[a-z]+/ig)
Oriol
  • 274,082
  • 63
  • 437
  • 513