Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
HI,

Can anyone tell me how to write regex string pattern?

What below code indicates-

Regex regex = new Regex("\\<[^\\>]*\\>");
Posted

while looking at the "Indicates" in your question and the reply to other solution posted. I though of sharing this very easy and precise article with you. It will explain you the Regex Fundamentals very easily.

Learn Regular Expressions (RegEx) with Ease


Further for the explanation of your posted Regex, You can have a look below

/\\<[^\\>]*\\>"/
\\ matches the character \ literally
< matches the character < literally
[^\\>]* match a single character not present in the list below
Quantifier: Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
\\ matches the character \ literally
> a single character in the list > literally (case sensitive)
\\ matches the character \ literally
>" matches the characters >" literally


And for any explanation in future, Do visit the following link.

Regex Tester/Explainer

Hope it will help. :)
 
Share this answer
 
Comments
Peter Leow 18-Mar-14 8:18am    
Good effort, Vick. +5!
VICK 18-Mar-14 8:19am    
Thanks Peter. :)
[no name] 19-Mar-14 2:22am    
Thank you for explaining.
VICK 19-Mar-14 4:49am    
You are welcome. :)
the original form should be :
\<[^\>]*\>

the extra \ is just to escape \ for the sake of c#.
It will match anything or nothing that is enclosed with '<' and '>'
The * means occurring zero or more times.
 
Share this answer
 
Comments
VICK 18-Mar-14 8:09am    
To the point and precise. My 5+.
Peter Leow 18-Mar-14 8:27am    
Thank you.
[no name] 19-Mar-14 2:23am    
description is very easy to understand. thank you.
Peter Leow 19-Mar-14 2:33am    
You are welcome.
Download this eBook to learn Regular Expressions

http://it-ebooks.info/book/920/[^]

Good Luck
 
Share this answer
 
for string pattern

"([a-zA-Z.'-]+),[ ]*([a-zA-Z.'-]+)"

Check this link

Refex to match string pattern mention
 
Share this answer
 
v2
Comments
[no name] 18-Mar-14 7:56am    
thanks for prompt reply. what * indicates? and is it compulsory to write [] - character class?

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