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?
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.
In Java, by default, the regular expression (regex) matching is case sensitive.
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.
You may try:
Regex regexText = new Regex(textToReplace, RegexOptions.IgnoreCase);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With