iYonatan
iYonatan

Reputation: 956

Regex to match Hebrew and English characters except numbers

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?

Upvotes: 23

Views: 29299

Answers (8)

Evgeniy
Evgeniy

Reputation: 149

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

Upvotes: 0

abbassix
abbassix

Reputation: 645

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

Upvotes: 0

genericUser
genericUser

Reputation: 7158

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!

Upvotes: 9

MegaSpaceHamlet
MegaSpaceHamlet

Reputation: 371

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

Upvotes: 1

Hebrew letters only:

/^[\u0590-\u05ea]+$/i

Upvotes: 1

Tom Shmaya
Tom Shmaya

Reputation: 91

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

Upvotes: 9

Explosion Pills
Explosion Pills

Reputation: 191749

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

/^[a-z\u0590-\u05fe]+$/i

Upvotes: 47

Strongbeard
Strongbeard

Reputation: 69

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

Upvotes: 2

Related Questions