无法使用regex.replace替换括号?

编程入门 行业动态 更新时间:2024-10-26 10:32:00
本文介绍了无法使用regex.replace替换括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用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替换括号?

本文发布于:2023-11-04 00:43:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556488.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:括号   regex   replace

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!