开发者

Filtering out bad characters using a regular expression

开发者 https://www.devze.com 2022-12-17 06:16 出处:网络
开发者_运维技巧I want to filter out the char ^ before searching something in a database. What will my regular expression look like if I want to achieve that the query will ignore the sign ^?

开发者_运维技巧I want to filter out the char ^ before searching something in a database.

What will my regular expression look like if I want to achieve that the query will ignore the sign ^?

I'm working with Visual Studio 2008, .NET 3.5, and C#.


You don't need a regex for that. You can simply do this:

myString = myString.Replace("^", "");


If you want to filter only that character, a simple String.Replace() call would suffice.

Anyway, if you want to use a regular expression, you must escape the ^, since it is a special character.

myString = Regex.Replace(myString, "\^+", String.Empty);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号