全局正则表达式替换函数从方括号创建 Html []
我有一些看起来像这样的现有代码:
[tag:cb cbid="12345" cbwidth="200" cbclassname="calloutbox" cbposition="left"] Lorem ipsum dolor sit amet, consectetur adipiscing elit.
[tag:cb cbid="123" cbwidth="200" cbclass="calloutbox2" cbposition="left"] Suspendisse eleifend enim a magna pretium porttitor.
我需要编写一个 VB .Net 全局函数来匹配这些 [tag:cb]
并采用可选参数并使用 Html 标记重写字符串。
<div id="12345" width="200" class="calloutbox" position="left">content (based on id)</div>
任何帮助表示赞赏。谢谢。
I have some existing code that looks something like this:
[tag:cb cbid="12345" cbwidth="200" cbclassname="calloutbox" cbposition="left"] Lorem ipsum dolor sit amet, consectetur adipiscing elit.
[tag:cb cbid="123" cbwidth="200" cbclass="calloutbox2" cbposition="left"] Suspendisse eleifend enim a magna pretium porttitor.
I need to write a VB .Net global function that will match these [tag:cb]
and take the optional parameters and rewrite the string with Html tags.
<div id="12345" width="200" class="calloutbox" position="left">content (based on id)</div>
Any help is appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个开始:
然后使用 capturegroup 1 和 2 来创建新字符串:
这将生成类似以下内容:
问题是它仍然具有
cbid="123"
等属性,而不是id="123"
。最好您希望通过另一个正则表达式运行它来替换所有出现的cb([^=]*)
并替换为 capturegroup 1。这将输出以下内容:
您现在要做的就是在 VB .Net 中实现它:)
您可以在此处查看第一部分的操作:http://regexr.com?2vbkq
第二部分在这里:http ://regexr.com?2vbl3
Here's a start:
And then you use capturegroup 1 and 2 to make the new string:
This will generate something like:
The problem is that it will still have attributes like
cbid="123"
instead ofid="123"
. Preferably you would like to run it through another regexp to replace all occurances ofcb([^=]*)
and replace with capturegroup 1.That would output the following:
All you have to do now is to implement it in VB .Net :)
You can see the first part in action here: http://regexr.com?2vbkq
and the second part here: http://regexr.com?2vbl3