-1

I have the following content...

database-host-12334-ireland
database-host-23233-london
database-host-32323-cardiff
backup-host-2323232-ireland
backup-host-3232323-london

I want to be able to search for all database-hosts and at the same time leave out the Ireland host.

I want the search to return only 2 hosts database hosts:

database-host-23233-london
database-host-32323-cardiff

I cant figure out how I can edit my regex lookup from ^database-host-[0-9].*

Any help would be appreciated, maybe its not even possible. Thanks

UPDATE TO PREVIOUS QUESTION:

Ok a bit more complicated this time, how would you go about excluding the one database ireland host from this list?

www.regexr.com/5gln4

database-host-12334.host.zone1.eu.ireland-1
database-host-12334.host.zone1.us.newyork-1
database-host-12334.host.zone2.uk.london-1
database-host-12334.host.zone3.uk.cardiff-1
database-host-12334.host.zone3.uk.belfast-1
backup-host-12334.host.zone2.uk.london-1
backup-host-12334.host.zone3.uk.cardiff-1
backup-host-12334.host.zone3.uk.belfast-1

I only want to return the database-hosts excluding Ireland one.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

1 Answers1

1

You may use a negative lookahead assertion to rule out the Ireland host:

database-host-\d+-(?!ireland)\w+

Demo

If you can't use lookarounds for some reason, another way to logically achieve what you want would be to use two regex patterns, one for whitelisting database hosts, and the other for blacklisting Ireland hosts:

database-host-\d+-\w+ && !(database-host-\d+-ireland)
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • This is brilliant thank you, it has me on the right track. Ok a bit more complicated this time, how would you go about excluding the one database ireland host from this list? https://regexr.com/5gln4 – vaguefaded Nov 20 '20 at 09:40