Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下字符串变量,我想将其用作 Regex.Replace 中有效字符模式的一部分:
string unreservedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~"; string input = "gzaHQ6PKUgQjXP+/dajkl==";
是否有一个简单的(希望是一个衬里)来替换中input不存在的字符unreservedChars?
input
unreservedChars
您可以尝试速记字符范围:
// returns "gzaHQPKUgQjXPdajkl" Regex.Replace("gzaHQ6PKUgQjXP+/dajkl==", @"[^a-zA-Z0-9-_.~]", "");