3

Need a bit help here, its pretty easy, suppose i have string "Hello {{name}}, you are {{face}}".

How can I process this string so that in return I'll get something like ["name","face"], any ideas to solve this in node js? thanks a bunch

Comments
  • 2
    Google "nunjucks template engine"
  • 3
    You can regular exp the groups within {{}}
  • 1
    I'm so sleepy so I'm not sure if I'm getting your requirements correctly.

    I'm assuming you want to pass in a string like "Hello mycroChip, you are human" and then have it return something like { name: "mycroChip", face: "human" }, right?

    In that case, you should probably use this:
    https://github.com/ishan-marikar/...
    It's a fork of a library a friend of mine did (which has been since archived) based on a similar module in python. It uses regular expressions to do that.

    npm install ishan-marikar/extract-values

    .. also, always review code before you import it into projects. Make that a habit.
  • 1
    Thanks for the input guys, I've also considered using libs.. but after google here and there, finally i used a regex which is:

    \{{.*?\}}

    Its solved now and really that simple, I think i need a break lol

    The specs should be able to get the parameter inside parentheses, I think thats all, once again thanks a bunch
Add Comment