I'm looking for a way to construct a RegExp object from a user input value that will match against some values which contains a dollar character $ (currency).
As I know this character must be escaped I have issues getting it to work correctly, especially in combination with other operators and characters.
I'm looking for to construct a RegExp that will work based on user input and hence it needs to be dynamic. Trying try to explain the scenario, something in this fashion:
User input: "$50"
or "50"
"$50" // match
"$50 + $5" // match as it matches on "$50"
"$500 + $50" // match as it matches on "$50"
"$500" // should not match
"$5000" // should not match
"$5.50" // should not match
user input: "$5000"
or "5000"
"$5000" // match
"$5,000" // match as it resembles the same value
"$5000 + $500" // match
"$5.000" // should not match
"$5000.50" // should not match
So basically it should only match the exact user input, with the exception of the dollar character ($), if there's a value that follows it but they are separated by a plus symbol (but still the same string), or if the value has a comma which is commonly used when writing larger numbers (for example 5,000).
Is this possible with a RegExp object?