Regex to match Hebrew and English characters except numbers
Asked Answered
D

8

23

I have a question: I want to do a validation for the first and the last name with RegEx. I want to do it with only Hebrew and English without numbers. Someone can help me to do that code?

Derman answered 31/7, 2014 at 19:27 Comment(1)
This seems like a good place for this link: kalzumeus.com/2010/06/17/…Gurdwara
S
47

Seemingly Hebrew has the range \u0590-\u05fe (according to this nice JavaScript Unicode Regex generator`.

/^[a-z\u0590-\u05fe]+$/i
Sayer answered 31/7, 2014 at 19:32 Comment(3)
Should we throw a $ in there as well for the end of the string?Dairying
Does it works with "change direction" unicodes? (RLM, LRM, \u200f \u200e). It could be a problem if the user changes from Hebrew to English and vice versa. My solution covers it https://mcmap.net/q/555381/-regex-to-match-hebrew-and-english-characters-except-numbersCarryingon
For .NET, one can use \p{IsHebrew} instead of \u0590-\u05fe (see learn.microsoft.com/en-US/dotnet/standard/base-types/…)Procurance
K
9

While the selected answer is correct about "Hebrew" the OP wanted to limit validation to only Hebrew and English letters. The Hebrew Unicode adds a lot of punctuation and symbols (as you can see in the table here) irrelevant for such validation. If you want only Hebrew letters (along with English letters) the regex would be:

/^[a-z\u05D0-\u05EA]+$/i

I would consider adding ' (single quote) as well, for foreign consonants that are missing in Hebrew (such as G in George and Ch in Charlie) make use of it along with a letter:

/^[a-z\u05D0-\u05EA']+$/i
Koenig answered 18/6, 2020 at 19:2 Comment(0)
C
8

English & Hebrew FULL regex

I'm using the above regex on my application. My users are just fine with it:

RegExp(r'^[a-zA-Z\u0590-\u05FF\u200f\u200e ]+$');

The regex supports:

  • English letters (includes Capital letters). a-zA-Z
  • Hebrew (includes special end-letters). \u0590-\u05FF
  • change direction unicodes (RLM, LRM). \u200f\u200e
  • White space.

Enjoy!

Carryingon answered 8/2, 2021 at 15:7 Comment(0)
M
2

Try this. Not sure if it will work. If not, these references should help.

[A-Za-z\u0590-\u05FF]*

Hebrew Unicode

Unicode in Regular Expressions

Maryannmaryanna answered 31/7, 2014 at 19:34 Comment(2)
Watch out, this matches the empty string and doesn't signify the start(^) or end($) of the string.Dairying
Also, instead of posting, "Not sure if it will work," just pop on JSFiddle/RegExPal to try it out. ;)Dairying
H
1

Hebrew letters only:

/^[\u0590-\u05ea]+$/i
Harlow answered 28/12, 2021 at 3:10 Comment(0)
C
1

You can also use \p{Hebrew} in your regex to detect any Hebrew unicode characters (if you're regex engine supports it).

Communist answered 10/2, 2022 at 17:12 Comment(0)
R
0

Well, the RegEx pattern is between two /'s. The i at the end is a flag that says to be indifferent to the cases. ^ means the start of a line, and $ means the end of a line. Brackets ([ and ]) means either of the characters inside the brackets. - means a range. Note that the characters are ordinal, so a-z or א-ת make sense; a-z means all letters from and include a to and include z. The same goes for א-ת. + means one or more of the preceding. So this pattern matches every sequence of letters from English or Hebrew.

P.S.: Also, note that the flavor of the RegEx is different in different languages and platforms. for example in Sublime Text the pattern would be: (?i)^[א-תa-z]+$.

/^[א-תa-z]+$/i
Roethke answered 15/1, 2023 at 14:0 Comment(0)
Y
0

Swift 5 This work for me: Hebrew, English

NSRegularExpression(pattern: "^[\\p{Hebrew} a-z]$",  options: .caseInsensitive).firstMatch(in: value, options: [], range: NSRange(location: 0, length: value.count))

Another languages you can get here - https://h2s1880.medium.com/how-to-use-regular-expressions-to-distinguish-national-languages-in-swift-c19d6d8d0a97

Yiddish answered 26/8, 2023 at 23:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.