问题
I need an expression that can accept only Hebrew letters and at least one space char.
I tried this for Hebrew letters, but it doesn't match sentences with Hebrew text and spaces:
result = Regex.IsMatch(txtName.Text, @"[\u05D0\u05D1\u05D2\u05D3\u05D4\u05D5\u05D6\u05D7\u05D8\u05D9\u05DA\u05DB\u05DC\u05DD\u05DE\u05DF\u05E0\u05E1\u05E2\u05E3\u05E4\u05E5\u05E6\u05E7\u05E8\u05E9\u05EA]");
How can I represent all the Hebrew letters and at least one space char in regEx?
回答1:
You are looking for expression similar to @"[\p{IsHebrew} ]+"
- at least one character either Hebrew or space. To match whole sentence - add begin/end anchors - @"^[\p{IsHebrew} ]+$"
.
For detailed explanation see regular expression with hebrew or english and C#/.Net Character Classes in Regular Expressions.
来源:https://stackoverflow.com/questions/26061633/regex-for-hebrew-and-symbols