Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match single character in .net regex

Tags:

c#

regex

According to the MSDN documentation, the . character

Matches any single character except \n.

In this case, why does this regex not match?:

Regex.IsMatch("c",@"[.]")
like image 477
richzilla Avatar asked Jan 09 '23 17:01

richzilla


1 Answers

You are matching [.] which means character .. Use just . to get your result. The [] mean any of the character inside. So by . loses its special meaning because of this.

See demo.

http://regex101.com/r/qC9cH4/19

c is being captured by the second group, not the first one.

like image 77
vks Avatar answered Jan 18 '23 21:01

vks