Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
string :
C#
<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

HTML
<k:1>
<k:2>


how to do this using Regx. Can anyone help me ?
Posted
Updated 11-Mar-15 1:40am
v3

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

Refer: The 30 Minute Regex Tutorial[^]
 
Share this answer
 
v2
Comments
[no name] 11-Mar-15 23:15pm    
agree
This pattern
C#
\<K:\d+\>

will match all tags beginning with "K:" and ending with any number.
 
Share this answer
 
v3
Comments
TheRealSteveJudge 11-Mar-15 11:12am    
@downvoter: Thank you! What is wrong with this answer?
It is the same regex pattern as solution 3.
Matt T Heffron 11-Mar-15 19:19pm    
+5 to "compensate"...
TheRealSteveJudge 12-Mar-15 3:54am    
Thank you Matt!
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900