var text = "Price: 123 dollar."
text.replace(/((\d+\.?\d+?)|(\d{1,3}(\,\d{3})+)) *([a-zA-Z]+)/, function(a,b,c){
document.write(a+" | "+b+" | "+c);
return;
}
Now The output is: 123 dollar | 123 | 123
But I need the output to be: 123 dollar | 123 | dollar
It works with the regex /\b((?:\d+.)?\d+) *([a-zA-Z]+)/
Can’t figure it out.. Why b and c are the same?!
Fix: The solution was to remove unnecessary capture groups:
/((?:\d+.?\d+?)|(?:\d{1,3}(?:\,\d{3})+)) *([a-zA-Z]+)/
Thanks @Mythril and @cababunga
Because you created more capture groups. Which means more parameters to the replace function, try this: