I need this string:
var x = 'Hi ${name}! How are you? ${name}, you are old! ${name} share with ${other} how do u ${feel}!'
I need to know using Regex how much distinct ${ANY_THING} exists. In example above i expect 3: ${name}, ${other}, ${feel}
I'm trying it:
x.match(\${([a-zA-Z]))
But the output is wrong :(
Thanks!
I find this solution at #regex IRC Channel by farn user:
output:
and
output:
:)
The code above would return
3
, as that's how many distinct items are in thex
string.JSFiddle: http://jsfiddle.net/cae6P/
PS: It's not possible to do it with regular expression only. You need to filter duplicates using the
.filter()
solution or some other similarTo match the syntax you want you need this: