lets suppose I have the following string "$1 $1 10 20 $11 3$1 30 $1 10 $1"
I want to replace $1 whenever it is in the beginning of the string, end of string or between two spaces. As an example, replacing $1 with 10, would produce: "10 10 10 20 $11 3$1 30 10 10 10"
I am trying with the following expression: "(\s\$1\s)|(^\$1\s)|(\s\$1$)"
Unfortunately, I'm not able to match the 2nd $1, as the space character seems to be captured by the first match. The result with this expression is: "10 $1 10 20 $11 3$1 30 10 10 10"
I am not experienced with regex, and I'm probably missing something here. How can i correct the expression? (Java) thank you