我正在尝试使用Regex.replace替换括号,但我总是有 这个错误: System.ArgumentException:解析": - )" - 太多了)。参数名称::-) 这是'我的代码: Regex.Replace(输入,": - )" ,img,RegexOptions.Compiled | RegexOptions.IgnoreCase); 知道为什么?任何解决方案? 谢谢 Steph
Hi, I''m trying to replace parenthesis using Regex.replace but I''m always having this error: System.ArgumentException: parsing ":-)" - Too many )''s. Parameter name: :-) Here''s my code: Regex.Replace(input,":-)","img",RegexOptions.Compiled | RegexOptions.IgnoreCase); Any idea why? Any solution? Thanks Steph
推荐答案括号在正则表达式中具有特殊含义;在前面使用反斜杠\) 匹配字面括号 - ------ --------------------------------------------- 使用Visual Build Pro自动化软件构建 http://www.visualbuild。 com / " Stephane" <圣****** @ discussions.microsoft>在留言中写道 新闻:A6 ********************************** @ microsof t ... Parentheses have special meaning in a regex; use a backslash \) in front to match on a literal parenthesis -- --------------------------------------------------- Automate your software builds with Visual Build Pro www.visualbuild/ "Stephane" <St******@discussions.microsoft> wrote in message news:A6**********************************@microsof t... 我正在尝试使用Regex.replace替换括号,但我总是有这个错误: System.ArgumentException:解析": - )" - 太多了)。参数名称: :-) 这是我的代码: Regex.Replace(输入,": - )"," img" ;,RegexOptions.Compiled | RegexOptions.IgnoreCase); 任何想法为什么?任何解决方案? 谢谢 Steph Hi, I''m trying to replace parenthesis using Regex.replace but I''m always having this error: System.ArgumentException: parsing ":-)" - Too many )''s. Parameter name: :-) Here''s my code: Regex.Replace(input,":-)","img",RegexOptions.Compiled | RegexOptions.IgnoreCase); Any idea why? Any solution? Thanks Steph
Stephane< St ****** @ discussions.microsoft>写道: Stephane <St******@discussions.microsoft> wrote: 我正在尝试使用Regex.replace替换括号,但我总是有这个错误: System.ArgumentException:解析" ;: - )" - 太多了)。参数名称::-) 这是我的代码: Regex.Replace(输入,": - )"," img",RegexOptions。编译| RegexOptions.IgnoreCase); I''m trying to replace parenthesis using Regex.replace but I''m always having this error: System.ArgumentException: parsing ":-)" - Too many )''s. Parameter name: :-) Here''s my code: Regex.Replace(input,":-)","img",RegexOptions.Compiled | RegexOptions.IgnoreCase);
Kyle已经回答了你的问题 - 但你真的有需要 使用正则表达式首先?为什么不直接使用 input.Replace(": - )"," img"); 如果你''重新尝试用另一个字符串替换一个字符串,而不使用任何正常表达式的特殊功能,这比使用String.Replace而不是正则表达式更简单。替换。 - Jon Skeet - < sk *** @ pobox> www.pobox/~skeet 博客: www.msmvps/jon.skeet 如果回复该群组,请不要给我发邮件
Kyle has answered your question - but do you actually have any need to use regular expressions in the first place? Why not just use input.Replace (":-)", "img"); If you''re trying to replace one string with another, without using any of the special features of regular expressions, it''s a lot simpler to use String.Replace than Regex.Replace. -- Jon Skeet - <sk***@pobox> www.pobox/~skeet Blog: www.msmvps/jon.skeet If replying to the group, please do not mail me too
我以为使用Regex.replace会比input.replace快得多。 有吗这两者之间真正的性能差异还是我只是浪费了3 小时试图让它工作? :-B 谢谢! Steph " Jon Skeet [C#MVP] "写道: I thought using Regex.replace would be much faster than input.replace. Is there a real performance difference between the two or I just wasted 3 hours trying to make it worked? :-D Thanks! Steph "Jon Skeet [C# MVP]" wrote: Stephane< St ****** @ discussion.microsoft>写道: Stephane <St******@discussions.microsoft> wrote: 我正在尝试使用Regex.replace替换括号,但我总是有这个错误: System.ArgumentException:解析" ;: - )" - 太多了)。参数名称::-) 这是我的代码: Regex.Replace(输入,": - )"," img",RegexOptions。编译| RegexOptions.IgnoreCase); I''m trying to replace parenthesis using Regex.replace but I''m always having this error: System.ArgumentException: parsing ":-)" - Too many )''s. Parameter name: :-) Here''s my code: Regex.Replace(input,":-)","img",RegexOptions.Compiled | RegexOptions.IgnoreCase);
Kyle已经回答了你的问题 - 但你真的有必要首先使用正则表达式吗?为什么不直接使用 input.Replace(": - )"," img"); 如果你试图用另一个字符串替换一个字符串,没有使用正则表达式的任何特殊功能,使用String.Replace比使用Regex.Replace要简单得多。 - Jon Skeet - < sk *** @ pobox> http:/ /www.pobox/~skeet 博客: http:// www .msmvps / jon.skeet 如果回复小组,请不要给我发邮件
Kyle has answered your question - but do you actually have any need to use regular expressions in the first place? Why not just use input.Replace (":-)", "img"); If you''re trying to replace one string with another, without using any of the special features of regular expressions, it''s a lot simpler to use String.Replace than Regex.Replace. -- Jon Skeet - <sk***@pobox> www.pobox/~skeet Blog: www.msmvps/jon.skeet If replying to the group, please do not mail me too
更多推荐
无法使用regex.replace替换括号?
发布评论