first, you need to escape the .
(.
matches 'anything', you want \.
to match ".") [weird - someone edited the question to fix that]
second, a lookahead looks ahead - it doesn't consume anything. so, even if you escape the .
, [_a-z0-9]+(?=\.|->)
is only consuming "hints6" (and then, looking ahead, confirming that the next character will be "."). after that, [_a-z0-9]+
fails to match the ".".
i don't really understand what you are trying to do. as far as i can see, [_a-z0-9]+(?:\.|->)[_a-z0-9]+
would do what you want, without any lookahead ((?:...)
is a grouping that doesn't bind to results).
in general, you don't need lookahead much, because you can just match. it's used mainly when you want to match a group, but for some (strange) reason need to check a specific case beforehand.
[edit:] if you just want to capture the two words then use ([_a-z0-9]+)(?:\.|->)([_a-z0-9]+)
(note that will capture two groups, one for each word).
[edit2:] if this is for a syntax highlighter then i think you could go with something that highlights either word. it's easier to show than explain:
(?:[_a-z0-9]+(?=(?:\.|->)[_a-z0-9]+)|(?<=[_a-z0-9]+(?:\.|->))[_a-z0-9]+)
that will highlight either "a word followed by .word" or "a word preceded by word.", which will highlight both words without highlighting the dot. they are two separate matches, but the syntax highlighter doesn't care about that (i assume).