csbukhari csbukhari - 1 year ago 103
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 Source


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

Hope it helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download