C# 替换多个[代码]块
我正在创建一个博客网站,允许用户在[code]代码内容[/code]中输入代码 在一篇博文中会有多个类似的[代码]块 我想用Regex找到每个[Code]块,然后用C# 替换多个[代码]块,c#,.net,regex,C#,.net,Regex,我正在创建一个博客网站,允许用户在[code]代码内容[/code]中输入代码 在一篇博文中会有多个类似的[代码]块 我想用Regex找到每个[Code]块,然后用 <pre>command "); 指数=米指数+米长度; m=m.NextMatch(); } if(索引
<pre>command
");
指数=米指数+米长度;
m=m.NextMatch();
}
if(索引<值.长度)
追加(值、索引、值、长度-索引);
返回result.ToString();
}
。RegexBuddy的解释:
\[code\](?<code>.*?)\[/code\]
要使其适用于[code][/code]
,请将其更改为:
…请记住,这只适用于单行块。此外,只有一个
code
组..不再有lang
组..因此请从C#中删除该组..。如果您找到一些有用的代码..为什么需要帮助?也许您有一个错误想与大家分享?如果您可以讨论y部分,这会有所帮助你被搞糊涂了。我被正则表达式搞糊涂了。匹配行。我想找到[Code]-[/Code]块并把它搞糊涂。感谢你的帮助。谢谢你的帮助。你太棒了:)
\[pre=(?<lang>[a-z]+)\](?<code>.*?)\[/pre\]
Match the character “[” literally «\[»
Match the characters “pre=” literally «pre=»
Match the regular expression below and capture its match into backreference with name “lang” «(?<lang>[a-z]+)»
Match a single character in the range between “a” and “z” «[a-z]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the character “]” literally «\]»
Match the regular expression below and capture its match into backreference with name “code” «(?<code>.*?)»
Match any single character that is not a line break character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the character “[” literally «\[»
Match the characters “/pre” literally «/pre»
Match the character “]” literally «\]»
\[code\](?<code>.*?)\[/code\]