Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ?= mean in a regular expression?

Tags:

regex

May I know what ?= means in a regular expression? For example, what is its significance in this expression:

(?=.*\d). 
like image 342
theraneman Avatar asked Oct 15 '09 07:10

theraneman


People also ask

What is ?= In python regex?

(?= ...) is a positive lookahead assertion. It matches if there is the part in parentheses after ?= matches at the current position, but it will not consume any characters for the match.

What does '!' Mean in regex?

It's a negative lookahead, which means that for the expression to match, the part within (?!...) must not match. In this case the regex matches http:// only when it is not followed by the current host name (roughly, see Thilo's comment). Follow this answer to receive notifications.

What does the regular expression a z0 9 \-] mean?

In a regular expression, if you have [a-z] then it matches any lowercase letter. [0-9] matches any digit. So if you have [a-z0-9], then it matches any lowercase letter or digit. You can refer to the Python documentation for more information, especially in the chapter 6.2-Regular Expression operations.

What is a regular expression language?

Regular Expression Language - Quick Reference. A regular expression is a pattern that the regular expression engine attempts to match in input text. A pattern consists of one or more character literals, operators, or constructs. For a brief introduction, see .NET Regular Expressions.

What does the backslash character (\) mean in a regular expression?

The backslash character (\) in a regular expression indicates that the character that follows it either is a special character (as shown in the following table), or should be interpreted literally. For more information, see Character Escapes.

How many characters can be in a regular expression?

The regular expression says: There may be any number of characters between the expression (?=. {8,}) (?=.* [a-z]) (?=.* [A-Z]) (?=.* [@#$%^&+=]) and the beginning and end of the string that is searched. Show activity on this post. So when you see this...

What is the difference between pipe and regex?

For example, the below regex matches google, gooogle, gooooogle, goooooogle, …. | Pipe, matches either the regular expression preceding it or the regular expression following it. For example, the below regex matches the date format of MM/DD/YYYY, MM.DD.YYYY and MM-DD-YYY. It also matches MM.DD-YYYY, etc. ?


1 Answers

?= is a positive lookahead, a type of zero-width assertion. What it's saying is that the captured match must be followed by whatever is within the parentheses but that part isn't captured.

Your example means the match needs to be followed by zero or more characters and then a digit (but again that part isn't captured).

like image 170
cletus Avatar answered Oct 14 '22 17:10

cletus