Regex are simple yet complex at times. Stuck to replace an expression having variables, assuming variable is of the following pattern:

```
\w+(\.\w+)*

```

I want to replace all the occurrences of my variable replacing dot (.) because i have to eventually tokenize the expression where tokenizer do not recognize variable having dots. So i thought to replace them with underscore before parsing. After tokenizing however i want to get the variable token with original value.

Expression:

```
(x1.y2.z3 + 9.99) + y2_z1 - x1.y2.z3

```

Three Variables:

```
x1.y2.z3

y2_z1

x1.y2.z3

```

Desired Output:

```
(x1_y2_z3 + 9.99) + y2_z1 - x1_y2_z3

```

* Question 1: How to use Regex replace in this case?
* Question 2: Is there any better way to address above mentioned problem because variable can have underscore so replacing dot with underscore is not a viable solution to get the original variable back in tokens?