Answered by:
Create regex pattern in c#.

Question
-
Hi All,
I am windows 8.1 store app developer in c#.I want to make a regex for my own custom string.It is possible to create regex? I have no idea how can I do that. I have found a regex for all link matching purpose like this
string pattern = @"(((https?|ftp|file)://)|(www\.)|(Www\.)|)[-a-zA-Z0-9+&@#/%?=~_|!:,.;]+\.(xxx|travel|tel|pro|post|org|net|name|museum|mobi|jobs|int|info|coop|"
+ "com|cat|biz|"
+ "asia|aero|ab|bc|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au"
+ "|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|"
+ "cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|"
+ "de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|"
+ "ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm"
+ "|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|"
+ "ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md"
+ "|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne"
+ "|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt"
+ "|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so"
+ "|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt"
+ "|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|"
+ "vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)([-a-zA-Z0-9+&@#/%?=~_|!:,.;]+)";
Regex regex = new Regex(pattern);
var matches = regex.Matches(source);//Here source is my passing stringI want to create a regex expression for those string which is given bellow
1) :)
2) :(
3) :D
4) (cool)
5) :O
6) ;)
7) ;(
8) (:|
9) :|
10) (kiss)
11) :P
12) :$
13) :^)
14) |-)
15) |-(
16) (inlove)
17) ]:)
18) (yn)
19) (yawn)
20) (puke)
21) (doh)
22) (angry)
23) (wasntme)
24) (party)
25) (worry)
26) (mm)
27) (nerd)
28) :x
29) (wave)
30) (facepalm)
31) (devil)
32) (angel)
33) (envy)
34) (wait)
35) (hug)
36) (makeup)
37) (chuckle)
38) (clap)
39) (think)
40) (bow)
41) (rofl)
42) (whew)
43) (happy)
44) (smirk)
45) (nod)
46) (shake)
47) (waiting)
48) (emo)
49) (y)
50) (n)
51) (handshake)
52) (highfive)
53) (heart)
54) (lalala)
55) (heidy)
56) (F)
57) (rain)
58) (sun)
59) (tumbleweed)
60) (music)
61) (bandit)
62) (tmi)
63) (coffee)
64) (pi)
65) (cash)
66) (flex)
67) (^)
68) (beer)
69) (d)
70) (o)
71) (ninja)
72) (*)
Please help me to create regex expression.
ThanQ
Ganesh
Friday, June 27, 2014 3:11 PM
Answers
-
Hi Mark,
I was resolved it from my end. The code is given bellow
string re2 = @"(\:\)|\:\(|\:(D)|\(cool\)|\:(O)|\;\)|\(\:\||\:\||\(kiss\)|\:(P)|\:[$]|\:\^\)|\|[-]\)|\|[-]\(|\(inlove\)|\]\:\)|\(yn\)|\(yawn\)|\(puke\)|\(doh\)|\(angry\)|\(wasntme\)|\(party\)|\(worry\)|\(mm\)|\(nerd\)|\:(x)|\(wave\)|\(facepalm\)|\(devil\)|\(angel\)|\(envy\)|\(wait\)|\(hug\)|\(makeup\)|\(chuckle\)|\(clap\)|\(think\)|\(bow\)|\(rofl\)|\(whew\)|\(happy\)|\(smirk\)|\(node\)|\(shake\)|\(waiting\)|\(emo\)|\(y\)|\(n\)|\(handshake\)|\(highfive\)|\(heart\)|\(lalala\)|\(heidy\)|\(F\)|\(rain\)|\(sun\)|\(tumbleweed\)|\(music\)|\(bandit\)|\(tmi\)|\(coffee\)|\(pi\)|\(cash\)|\(flex\)|\(\^\)|\(beer\)|\(d\)|\(o\)|\(ninja\)|\(\*\))";
Regex r = new Regex( re2);ThanQ
Ganesh
- Marked as answer by Anne Jing Monday, June 30, 2014 1:52 AM
Saturday, June 28, 2014 5:54 AM
All replies
-
System.Text.RegularExpressions.RegEx is a .NET class that is supported in Store apps:
http://msdn.microsoft.com/en-us/library/windows/apps/system.text.regularexpressions.regex.aspx
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.Friday, June 27, 2014 7:52 PMModerator -
Hi Matt,
ThanQ for your valuable reply.I know that System.Text.RegularExpressions.RegEx is a .NET class that is supported in Store apps but my concern is that how can I create pattern for my won string which I have posted above in my thread.I have no idea how can I create it. Please help me to create pattern for the above posted string.It is very important for me.
ThanQ
Ganesh
Saturday, June 28, 2014 4:13 AM -
Hi Mark,
I was resolved it from my end. The code is given bellow
string re2 = @"(\:\)|\:\(|\:(D)|\(cool\)|\:(O)|\;\)|\(\:\||\:\||\(kiss\)|\:(P)|\:[$]|\:\^\)|\|[-]\)|\|[-]\(|\(inlove\)|\]\:\)|\(yn\)|\(yawn\)|\(puke\)|\(doh\)|\(angry\)|\(wasntme\)|\(party\)|\(worry\)|\(mm\)|\(nerd\)|\:(x)|\(wave\)|\(facepalm\)|\(devil\)|\(angel\)|\(envy\)|\(wait\)|\(hug\)|\(makeup\)|\(chuckle\)|\(clap\)|\(think\)|\(bow\)|\(rofl\)|\(whew\)|\(happy\)|\(smirk\)|\(node\)|\(shake\)|\(waiting\)|\(emo\)|\(y\)|\(n\)|\(handshake\)|\(highfive\)|\(heart\)|\(lalala\)|\(heidy\)|\(F\)|\(rain\)|\(sun\)|\(tumbleweed\)|\(music\)|\(bandit\)|\(tmi\)|\(coffee\)|\(pi\)|\(cash\)|\(flex\)|\(\^\)|\(beer\)|\(d\)|\(o\)|\(ninja\)|\(\*\))";
Regex r = new Regex( re2);ThanQ
Ganesh
- Marked as answer by Anne Jing Monday, June 30, 2014 1:52 AM
Saturday, June 28, 2014 5:54 AM