csbukhari csbukhari - 4 months ago 15
Node.js Question

How to count curly brackets in nodejs

I'm trying to find a way to count how many curly brackets in any string.

For example:

Dear {0}, Your one time password is {1} Thanks


I found https://www.npmjs.com/package/matchstick but it does not work as I need.

Answer

Try:

var count = ("Dear {0}, Your one time password is {1} Thanks".match(/{|}/g) || []).length;

Hope it helps.

Comments