Regex for Hebrew, English, characters

as part of the small program that I am writing, I need to filter out the String input, which can be "gibrish" (any character in UTF8), the input can be Hebrew and / or English, but also have all the usual characters, such as:?% $! @'_' etc.

A friend suggested using a regular expression, but because of my inexperience with using it, I come to you for advice.

how can I create a C # function to check the input text and if it is not "correctly" returns false

My attempt:

public static bool shortTest(string input) { string pattern = @"^[אבגדהוזחטיכלמנסעפצקרשתץףןםa-zA-Z0-9\_]+$"; Regex regex = new Regex(pattern); return regex.IsMatch(input); } 

all characters after "[" and "a" are Hebrew

+4
source share
2 answers

For Hebrew letters , in C # you can do something like this:

 return System.Text.RegularExpressions.Regex.IsMatch(value, @"^[א-ת]+$"); 

enjoy =)

+4
source

You can use the character class \p{IsHebrew} instead of listing all the characters in Hebrew, \ w for [a-zA-Z0-9_] and \ s for spaces, tabs, newlines. You can add too many points, a comma ... Example:

 ^[\p{IsHebrew}\w\s,.?!;:-]+$ 

or

 ^[\p{IsHebrew}\w\s\p{P}]+$ 

\ p {P} means all spelling icons (as far as I know: .,?!:;-_(){}[]\/'"&#@%* )

+2
source

Source: https://habr.com/ru/post/1479279/


All Articles