Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this regexp mean - "\p{Lu}"?

I stumble across this regular expression in c# I would like to port to javascript, and I do not understand the following:

[-.\p{Lu}\p{Ll}0-9]+ 

The part I have a hard time with is of course \p{Lu}. All regexp websites I visited never mention this modifier.

Any idea?

like image 250
Mikaël Mayer Avatar asked Sep 22 '14 15:09

Mikaël Mayer


People also ask

What is the meaning of RegExp?

Regular Expressions (Regex) Regular Expression, or regex or regexp in short, is extremely and amazingly powerful in searching and manipulating text strings, particularly in processing text files. One line of regex can easily replace several dozen lines of programming codes.

What does .*?) Mean in regex?

(. *?) matches any character ( . ) any number of times ( * ), as few times as possible to make the regex match ( ? ). You'll get a match on any string, but you'll only capture a blank string because of the question mark.

What is RegExp used for?

A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation.

What does regex 0 * 1 * 0 * 1 * Mean?

Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.


1 Answers

These are considered Unicode properties.

The Unicode property \p{L} — shorthand for \p{Letter} will match any kind of letter from any language. Therefore, \p{Lu} will match an uppercase letter that has a lowercase variant. And, the opposite \p{Ll} will match a lowercase letter that has an uppercase variant.

Concisely, this would match any lowercase/uppercase that has a variant from any language:

AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz 
like image 135
hwnd Avatar answered Sep 22 '22 01:09

hwnd