Regex for Hebrew and symbols

馋奶兔 提交于 2021-02-16 20:07:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!