如何用模式本身中存在的字符串替换模式。 [英] How do I replace a Pattern with string present in pattern itself.
本文介绍了如何用模式本身中存在的字符串替换模式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果用户输入< get property =name>所以我希望它被替换为属性字典中的键name的值。
templete = Regex.Replace(templete, < get property =(。*)>,?)
我可以用什么代替?在上面的代码中,以便< get>标签将被字典的值替换,其中key是属性属性的值。
示例
1.如果标签是< ; get property =name>因此应该用字典(名称)替换。
2.如果标签是< get property =age>因此应该用字典(年龄)替换。
解决方案
尝试:
公共 共享 ReplaceName 作为 新正则表达式( < get property =(?< Name>。 *)>)
...
Dim 结果 As 字符串 = ReplaceName.Replace( < ; get property =John Smith>, dictionary(
{名称} )跨度>)
If the user inputs <get property = "name"> so I want it to be replaced with the value of key "name" present in properties dictionary.
templete = Regex.Replace(templete, "<get property = ""(.*)"">", ?)
What can I write in place of ? in the above code so that the <get> tag will be replaced by the value of dictionary where key is the value of property attribute.
Example
1. If the tag is <get property = "name"> so it should be replaced with dictionary("name").
2. If the tag is <get property = "age"> so it should be replaced with dictionary("age").
解决方案
Try:
Public Shared ReplaceName As New Regex("<get property = ""(?<Name>.*)"">") ... Dim result As String = ReplaceName.Replace("<get property = ""John Smith"">", "dictionary(""
{Name}"")")
这篇关于如何用模式本身中存在的字符串替换模式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文