Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does regular in regex/"regular expression" mean?

What does the "regular" in the phrase "regular expression" mean?

I have heard that regexes were regular at one time, but no more

like image 802
barlop Avatar asked Jan 26 '11 14:01

barlop


People also ask

What is regular in regular expression?

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 is difference [] and () in regex?

[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9. (a-z0-9) -- Explicit capture of a-z0-9 .

What does '$' mean in regex?

$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.

What does \\ s+ mean in regex?

The plus sign + is a greedy quantifier, which means one or more times. For example, expression X+ matches one or more X characters. Therefore, the regular expression \s matches a single whitespace character, while \s+ will match one or more whitespace characters.


1 Answers

The regular in regular expression comes from that it matches a regular language.

The concept of regular expressions used in formal language theory is quite different from what engines like PCRE call regular expressions. PCRE and other similar engines have features like lookahead, conditionals and recursion, which make them able to match non-regular languages.

like image 90
Sebastian Paaske Tørholm Avatar answered Oct 14 '22 07:10

Sebastian Paaske Tørholm