Regex.Replace正规表达式问题

sillyfox 2003-08-19 01:18:13
chr是以下字符串:
<font color=#F5F5DC>adfa</font><font color=#F5F5DC>adfa</font>

然后:
Regex.Replace(chr,@"<font color=(?<x>[^\]]*)>(?<y>[^\]]*)</font>",@"[color=$1]$2[/color]",

得到的为什么是:
[color=#F5F5DC>adfa</font><font color=#F5F5DC]adfa[/color]
而不是
adfaadfa

如果要得到adfaadfa应该怎么写?
...全文
34 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
saucer 2003-08-19
  • 打赏
  • 举报
回复
the problem is with

[^\]]

look at your original string, where is "]"? you probably mean ">" or "<"
sillyfox 2003-08-19
  • 打赏
  • 举报
回复
思归大哥能不能帮我解释一下?
saucer 2003-08-19
  • 打赏
  • 举报
回复
string chr = "<font color=#F5F5DC>adfa</font><font color=#F5F5DC>adfa</font>";
chr = Regex.Replace(chr,@"<font\s+color=(?<x>[^>]*)>(?<y>[^<]*?)</font>",@"[color=${x}]${y}[/color]", RegexOptions.IgnoreCase);
正则表达式工具:JGsoft RegexBuddy v3.4.2 零售版无需要注册激活 正则表达式 - 正则表达式工具 JGsoft RegexBuddy v3.4.2 Retail JGsoft RegexBuddy 是一款正则表达式工具。它是你使用正则表达式时的最好的助手。容易创建完全符合你的要求的正则表达式。清除地理解其他人写的复杂的正则表达式。通过示例字符串和文件,快速测试任意正则表达式,防止在处理真实数据时发生错误。根据你使用的特定的编程语言自动在你的源代码中使用正则表达式代码片断。收集归档正则表达式例库以便将来重用。可以把RegexBuddy整合到你喜好的搜索和编辑工具里,以便快速使用。 RegexBuddy 使用 RegexBuddy 可以创建规范的正规表达式。该软件可以编译由其它软件编写的复杂的正规表达式。使用纯英文模块代替标准的 Regex 语法。在样本行和文件上测试任何规范的表达式,防止在实际数据上发生错误。通过分步完成真实的匹配过程来进行调试而不是单凭猜测。可以在你的自动地调整为 C#, VB.NET, Java, C, C++, Delphi, Perl, PHP, Python, JavaScript 和 Ruby 特殊细节的带有代码摘录的源代码当中使用 RegexRegexBuddy is your perfect companion for working with regular expressions. Easily create regular expressions that match exactly what you want. Clearly understand complex regexes written by others. Quickly test any regex on sample strings and files, preventing mistakes on actual data. Debug without guesswork by stepping through the actual matching process. Use the regex with source code snippets automatically adjusted to the particulars of your programming language. Collect and document libraries of regular expressions for future reuse. GREP (search-and-replace) through files and folders. Integrate RegexBuddy with your favorite searching and editing tools for instant access. History - http://www.regexbuddy.com/history.html Release year: 2010 Site: http://www.regexbuddy.com OS: Windows 98, ME, NT4, 2000, XP, Vista, and 7 Language: Eng. Activation/Crack/Serial/etc: It is not required (Full) Size: 9.34 MB
正则表达式工具 JGsoft RegexBuddy v3.4.2 Retail JGsoft RegexBuddy 是一款正则表达式工具。它是你使用正则表达式时的最好的助手。容易创建完全符合你的要求的正则表达式。清除地理解其他人写的复杂的正则表达式。通过示例字符串和文件,快速测试任意正则表达式,防止在处理真实数据时发生错误。根据你使用的特定的编程语言自动在你的源代码中使用正则表达式代码片断。收集归档正则表达式例库以便将来重用。可以把RegexBuddy整合到你喜好的搜索和编辑工具里,以便快速使用。 RegexBuddy 使用 RegexBuddy 可以创建规范的正规表达式。该软件可以编译由其它软件编写的复杂的正规表达式。使用纯英文模块代替标准的 Regex 语法。在样本行和文件上测试任何规范的表达式,防止在实际数据上发生错误。通过分步完成真实的匹配过程来进行调试而不是单凭猜测。可以在你的自动地调整为 C#, VB.NET, Java, C, C++, Delphi, Perl, PHP, Python, JavaScript 和 Ruby 特殊细节的带有代码摘录的源代码当中使用 RegexRegexBuddy is your perfect companion for working with regular expressions. Easily create regular expressions that match exactly what you want. Clearly understand complex regexes written by others. Quickly test any regex on sample strings and files, preventing mistakes on actual data. Debug without guesswork by stepping through the actual matching process. Use the regex with source code snippets automatically adjusted to the particulars of your programming language. Collect and document libraries of regular expressions for future reuse. GREP (search-and-replace) through files and folders. Integrate RegexBuddy with your favorite searching and editing tools for instant access. History - http://www.regexbuddy.com/history.html Release year: 2010 Site: http://www.regexbuddy.com OS: Windows 98, ME, NT4, 2000, XP, Vista, and 7 Language: Eng. Activation/Crack/Serial/etc: It is not required (Full) Size: 9.34 MB

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧