tags:

views:

77

answers:

3
/(?![a-z]+:)/

Anyone knows?

+2  A: 

according to Regex Buddy (a product i highly recommend):

Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?![a-z]+:)»
   Match a single character in the range between “a” and “z” «[a-z]+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
   Match the character “:” literally «:»
Scott Evernden
+3  A: 

the / are delimiters.

?! is negative lookahead.

[a-z] is a character class (any character in the a-z range)

+ is one-or-more times of the preceding pattern ([a-z] in this case)

: is just the colon literal

It roughly means "look ahead and make sure there are no alpha characters followed by a colon".

This regex would make more sense if it had a start of string anchor: /^(?![a-z]+:/, so it wouldn't match abc: (like one of the other answers say), but without the (^) I don't know how useful this is.

Aillyn
A: 

(?!REGEX) is the syntax for negative lookahead. Check the link for an explanation of lookaheads.

The regex fails if the pattern [a-z]+: appear in the string from the current position. If the pattern is not found, regex would succeed, but won't consume any characters.

It would match 123: or abc but not abc:

It would match the : in abc:.

Amarghosh
Nope, that's [not right.](http://rubular.com/r/sGqgeS5yPi). It still matches `abc:`
Aillyn
@Aillyn I don't see how the regex would be useful without some pattern before or after the lookahead.
Amarghosh
@Amarghosh Me neither
Aillyn