(?<=.*\$)\d+,?\d+(?=.*)|(?<=.*)\d+,?\d+(?=\$)
You will have to use replace method to remove the commas if any.
replace method[
^]
The explanation of the regex pattern:
. matches any character except newline
* means zero or more times
\$ refer to a $ sign
So, .*\$ matches zero or more characters followed by a $ sign
(?<=.*\$) will match a position immediately followed by zero or more characters followed by a $ sign
\d matches any digit
+ means one or more times
So, \d+ matches one or more digits
? means zero or one time
So, ,? matches zero or one comma
(?=.*) will match a position immediately precede a zero or more characters
Putting them together you get (?<=.*\$)\d+,?\d+(?=.*) that matches any number preceded by $ sign.
| means OR
(?<=.*)\d+,?\d+(?=\$) matches any number followed by $ sign.