1

I need to check below mentioned special characters as well extended Latin characters in my data.

Special characters: ~!@©#$%^&*()_+{}|:"<>?``€[]\;',./

Diacriticals: é, ö, ò, etc

I have tried [^a-z], but it does not work as I need, it also captures unwanted characters.

Could you please help me to suggest the correct regular expression?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Rakesh
  • 313
  • 1
  • 3
  • 14

1 Answers1

3

In .NET, you can use special character classes, too. The letters you provided come from \p{IsLatin-1Supplement} Unicode character set.

The regex then can be

[\p{IsLatin-1Supplement}~!@©#$%^&*()_+{}|:"<>?`€\[\]\\;',./]+

or

[\p{IsLatin-1Supplement}\p{P}\p{S}]+

since the symbols you provided come from symbols and punctuation Unicode character sets.

Sample code to match single characters from the character class:

var rx = new Regex(@"[\p{IsLatin-1Supplement}\p{P}\p{S}]");
var str = "~!@©#$%^&*()_+{}|:\"<>?€[]\\;',./`éöò";
var all = rx.Matches(str).Cast<Match>().ToList();

Output (in VS2012):

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Hello, I am also looking for regular expression for Valid price value like 100,100.00,and number should be without negative sign....is it possible using regular expression – Rakesh Apr 02 '15 at 11:45
  • @Rakesh: I do not know what exactly you are looking for. If it is live validation, then, it is not that easy since you'll have to use look-aheads. If not, it is really simple. BUT for price validation, I'd just use C# Decimal.TryParse() (https://msdn.microsoft.com/en-us/library/ew0seb73(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1). Please post your question, and you'll surely get an anwer. – Wiktor Stribiżew Apr 02 '15 at 11:54
  • Hello, Please find question related to price validations http://stackoverflow.com/questions/29415527/c-sharp-price-validation-using-regular-expression-other-way – Rakesh Apr 02 '15 at 14:31
  • Stribizhev: I more help I required which I posted on http://stackoverflow.com/questions/29790137/c-sharp-regex-remove-string-which-developed-only-combination-of-special-charter – Rakesh Apr 22 '15 at 07:06