Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ignore case sensitive in regex.replace?

I have this code to search in a string and replace some text with other text:

Regex regexText = new Regex(textToReplace);
retval = regexText.Replace(retval, Newtext);

textToReplace may be "welcome" or "client" or anything.

I want to ignore case for textToReplace so that "welcome" and "Welcome" both match.

How can I do this?

like image 204
Khalid Omar Avatar asked Jan 19 '11 16:01

Khalid Omar


People also ask

Is C# string replace case-sensitive?

The String. Replace() method allows you to easily replace a substring with another substring, or a character with another character, within the contents of a String object. This method is very handy, but it is always case-sensitive.

Are regex matches case-sensitive?

In Java, by default, the regular expression (regex) matching is case sensitive.

Is replace case-sensitive in JS?

JavaScript String Replace | Case Insensitive. The . replace function in JavaScript helps developers replace all the occurrences of a string in a text. However, many of us developers use this method in the wrong way while writing the code.


1 Answers

You may try:

Regex regexText = new Regex(textToReplace, RegexOptions.IgnoreCase);
like image 89
petro.sidlovskyy Avatar answered Oct 05 '22 18:10

petro.sidlovskyy