Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 943
iYonatan Avatar asked Jul 31 '14 19:07

iYonatan


People also ask

What does regex (? S match?

i) makes the regex case insensitive. (? s) for "single line mode" makes the dot match all characters, including line breaks.

Can you use regex with numbers?

The regex [0-9] matches single-digit numbers 0 to 9. [1-9][0-9] matches double-digit numbers 10 to 99. That's the easy part. Matching the three-digit numbers is a little more complicated, since we need to exclude numbers 256 through 999.

Which regular expression character matches on any digit?

\d (digit) matches any single digit (same as [0-9] ). The uppercase counterpart \D (non-digit) matches any single character that is not a digit (same as [^0-9] ).

How do I match a pattern in regex?

Regular expressions, called regexes for short, are descriptions for a pattern of text. For example, a \d in a regex stands for a digit character — that is, any single numeral 0 to 9. Following regex is used in Python to match a string of three numbers, a hyphen, three more numbers, another hyphen, and four numbers.


Video Answer


4 Answers

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!

like image 144
genericUser Avatar answered Oct 18 '22 07:10

genericUser


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
like image 29
Tom Shmaya Avatar answered Oct 18 '22 05:10

Tom Shmaya


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

/^[a-z\u0590-\u05fe]+$/i
like image 47
Explosion Pills Avatar answered Oct 18 '22 05:10

Explosion Pills


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

like image 2
Strongbeard Avatar answered Oct 18 '22 05:10

Strongbeard