查找标签之间的文本,并与标签替换它沿 [英] Finding text between tags and replacing it along with the tags
本文介绍了查找标签之间的文本,并与标签替换它沿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的正则表达式模式之间找到文本 [代码]
和 [/代码]
标签:
I am using The following regex pattern to find text between [code]
and [/code]
tags:
(?<=[code]).*?(?=[/code])
它返回我什么是这两个标记之间封闭的,如这样的: [代码]返回您好; [/代码]
给我回有你好;
It returns me anything which is enclosed between these 2 tags, e.g. this: [code]return Hi There;[/code]
gives me return Hi There;
.
我需要用正则表达式帮助标签替换整个文本的以及。
I need help with regex to replace entire text along with the tags.
推荐答案
使用这样的:
var s = "My temp folder is: [code]Path.GetTempPath()[/code]";
var result = Regex.Replace(s, @"\[code](.*?)\[/code]",
m =>
{
var codeString = m.Groups[1].Value;
// then you have to evaluate this string
return EvaluateMyCode(codeString)
});
这篇关于查找标签之间的文本,并与标签替换它沿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文