C#字符串表达式 [英] C# String Expression

查看:108
本文介绍了C#字符串表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string:

<K:1>Guru</K:1> bla .. bla .. bla ..<K:2>Raja</K:2>





在上面的字符串中,我们需要在数组中获取标签名称









In the above string, We need to get the tags names in a array

like

<k:1>
<k:2>





如何使用Regx执行此操作。任何人都可以帮助我吗?



how to do this using Regx. Can anyone help me ?

推荐答案

试试这个正则表达式模式:

Try this Regex pattern:
@"<K:\d+>"



参考: 30分钟正则表达式教程 [ ^ ]


此模式

This pattern
\<K:\d+\>



将匹配以K:开头并以任意数字结尾的所有标签。


will match all tags beginning with "K:" and ending with any number.


如果所有标签都相同(< k:number) xmlns:k =#unknown>)您可以与\< k:\d {1} \>匹配其中:

\<匹配完全<

K:匹配精确K :(尽管你也可能需要逃脱:

\ n {1}只匹配一个数字

\>匹配完全>



如果这有帮助,请花时间接受解决方案。下次寻找解决方案时,有些网站可以帮助您创建自己的正则表达而无需任何预知。



谢谢。
If all tags are the same (<k:number xmlns:k="#unknown">) you can match with \<k:\d{1}\> where:
\< matches exact <
K: matches exact K: (although you might have to escape : too)
\d{1} matches exactly one number
\> matches exact >

If this helps please take time to accept the solution. And next time look for the solution, there are sites that help you create your own regexes without any foreknowledge.

Thank you.


这篇关于C#字符串表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆