I tried to use `regexprep` to solve a problem - I'm given a string, that represents a function; it contains a patterns like these: `'sin(arcsin(f))'` where `f` - any substring; and I need to replace it with simple `'f_2'`. I successfully used `regexprep` unless I face with such string:

```
str = 'sin(arcsin(sin(arcsin(f_2))))*x^2';
str = regexprep(str, 'sin\(arcsin\((\w*)\)\)','$1');

```

it returns

```
str =

sin(arcsin(f_2))*x^2

```

But I want it to be

```
str =

f_2*x^2

```

Is there any way to solve it (except obvious solution with for-loops).