fire
fire

Reputation: 21531

Exclude beginning string from regex

I have a piece of regex that looks like this:

/^.*website.localdev$/

This matches website.localdev as well as any subdomain like www.website.localdev fine.

I need to adapt it to exclude a string ("foo") at the beginning of the regex, so that "website.localdev" and "www.website.localdev" still matches but "foo.website.localdev" does not.

Upvotes: 0

Views: 101

Answers (1)

Uri Agassi
Uri Agassi

Reputation: 37409

You should use negative lookahead:

/^(?!foo\.).*?website.localdev$/

You can see it in action on rubular

Upvotes: 2

Related Questions