Click here to Skip to main content
15,867,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Below is my input and expecting output

Input

text text text text text text
text text text text text text
text text text text text text
text text text text text text
text text text text text text
text text text text text text­


Expecting Output
<safa>

This is my regex find and replace coding
C#
richTextBox2.Text = richTextBox2.Text.Replace("ක([^]*)ග", "<safa>");


My problem is, when I'm using this regex patter in notepad++ it's working and perfectly replaced, but here C#, replace is not working, please advise

What I have tried:

This is my regex find and replace coding
C#
richTextBox2.Text = richTextBox2.Text.Replace("ක([^]*)ග", "<safa>");
Posted
Updated 12-Apr-16 2:50am
Comments
Gautham Prabhu K 12-Apr-16 8:32am    
Where is the Regx object in your replace statement?
abdulsafran 12-Apr-16 8:34am    
using System.Text.RegularExpressions; is already declared at the top
abdulsafran 12-Apr-16 8:41am    
Please advise from an example?

You are calling the String.Replace method but you must call the Regex.Replace Method (String, String) (System.Text.RegularExpressions)[^]:
C#
Regex rgx = new Regex("ක([^]*)ග");
string result = rgx.Replace(richTextBox2.Text, "<safa>");
richTextBox2.Text = result;
</safa>
 
Share this answer
 
I found the solution. Thank you

C#
string replacedString = Regex.Replace(richTextBox1.Text, "ක([^ග]*)ග", @"<safa>");
            richTextBox1.Text = replacedString;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900