trt
trt

Reputation: 21

Find pattern and replace to another pattern string

I tried to check if string contains some patterns string For example: '4+3+6**4'.

I want replace the pattern ** to pow(x,y).

so i want the string will be 4+3+pow(6,4).

i want to know if there any way by 'Regex'.

trt.

Upvotes: 1

Views: 103

Answers (2)

Avinash Raj
Avinash Raj

Reputation: 174696

Just capture the number which exists before and after to ** along with the match ** and then replace the match with pwo($1,$2) .

Regex.Replace(string, @"(\d+)\*\*(\d+)", "pwo($1,$2)");

Upvotes: 2

vks
vks

Reputation: 67968

(\d+)\*{2}(\d+)

You can use this.Replace by pow($1,$2).See demo.Use verbatim mode @.

https://regex101.com/r/oF9hR9/15

Upvotes: 1

Related Questions