Question

I'm trying to validate url which doesn't contain login before .com at the end, but the regex at here is not validating the url properly.

I've used the lazy quantifier, but it is still consuming login string before moving to (?!login) part, and it is not backtracking. Could anyone please tell me what wrong I'm doing?

Was it helpful?

Solution

Here is a changed version, that says "Match some characters ; immediately preceding the end is not "login", and immediately following is ".com".

The problem in your part was: you had two lookaheads, looking ahead from the same position. It read: "some string, that is followed by something that at the same time is not "login" and is ".com". Indeed, ".com" is not "login", so that's what you matched.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top