1

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.

4
  • 4
    have you try anything? Commented May 12, 2015 at 7:31
  • When you say pwo, do you mean pow? Commented May 12, 2015 at 7:35
  • Do you also want to count the pow(6,4) so that the output is 4+3+1296, or just leave it as a string? Commented May 12, 2015 at 7:51
  • 1
    @trt: If I were you, I'd mark as correct the answer with correct output, and the one that was provided first. Commented May 12, 2015 at 8:08

2 Answers 2

2

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)");
Sign up to request clarification or add additional context in comments.

1 Comment

I guess you should have edited your answer rather than the question in the first place :)
1
(\d+)\*{2}(\d+)

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.