tags:

views:

95

answers:

2

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

(?=.*\d).
A: 

(?=pattern) is a zero-width positive lookahead assertion. For example, /\w+(?=\t)/ matches a word followed by a tab, without including the tab in $&.

Michael Foukarakis
That seemed like an unnecessarily snarky answer -- google doesn't accept ?= as something to search for, and to find out in other ways you'd probably need to know about regex assertions in the first place.
olliej
-1 for being rude (Google search). There's completely uncalled for.
cletus
I did Google for this one. Let me know what search terms you put for this one. The normal regex online references did not have ?= pattern information.
theraneman
-1 - Your search - "?=" - did not match any documents.
bdonlan
Search terms: 'regular expressions'. I'm sorry if I came off as rude, but it really was the simplest of searches.
Michael Foukarakis
I think it's OK to suggest people search by themselves.
Kinopiko
cletus
@cletus: Yes, Google does search for something. Since that *something* also appears on a number of other places, it might be sensible to avoid redundancy. Yet what do I do? I enable it. :)
Michael Foukarakis
Artelius
Googling is difficult, but not impossible http://www.google.com/search?q=regular+expression+question+mark+equals
Amarghosh
+3  A: 

?= 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).

cletus
Thanks cletus. Searching for information on this was not easy with a typical search engine :).
theraneman