variables from plain text Javascript

122 views Asked by At

I am using node on my backend and i have emails with from clients with feedback about a restaurant.

I have parsed the email and they now are now plain text but i want to extract variables from this text.

for example:

All customers have filed out Favorite food:

as an example again lets say that Favorite food : Pizza

How do i parse this plain text variable of Pizza so i can turn it into an variable for use later?

My best idea right now is to ensure that the emails i am recieving have a line break between each statement and then detect the line break, locate the known key 'favorite food' and then pick up all the charecters from there to the break.

But it feels very inelegant. Any suggestions?

1

There are 1 answers

0
mdworld On

Is it by any means possible to use a form instead of an email? In that case you could make a simple form and you can read the POST params with node. An example of a simple form:

<form action="https://httpbin.org/post" method="post">
  <select name="favoritePizza">
    <option>hawai</option>
    <option>cheese</option>
  </select>
  <input type="submit" />
</form>

https://jsfiddle.net/mdvanes/nrjufLvd/