Whats the best way in VCL to match a list of AS names using a regex pattern?

like for example i want to only allow traffic from a list of as name like client.as.name ~ "verizon|att|fastly
is that a valid regex?

Hi @johnnymets176

This is possible to do, but your example wasn’t quite right.

I’ve put together an example fiddle for you that demonstrates a working regex:

You’ll need to tweak it to fit your requirements, but essentially you needed a set of parentheses around the alternators, so instead of "verizon|att|fastly" you needed "(verizon|att|fastly)".

Hope this helps.

hi @Integralist

thanks for the help! would this setup also work for IPs, im getting errors trying that as well.

You could match IP addresses using regex, but it’s not usually the best way :slight_smile:

Try using an Access control list:

what is the best way to match ip via a regex?

Hi @johnnymets176

Validating an IP can be quite complex.

It’s easier if you’re trying to match IPv4 and IPv6 individually rather than a single regex to match both, but even then the individual regexes can become long and difficult to decipher. The following links demonstrate this.

A cursory Google for “regex to match IPv4” reveals that there are a myriad of approaches that can be taken: regex - Validating IPv4 addresses with regexp - Stack Overflow

Doing the same for IPv6 suggests (from multiple sources) that there isn’t a regex that can actually match all possible permutations. To validate IPv6 accurately/completely requires defining multiple separate regexes: oracle - Regular Expression (RegEx) for IPv6 Separate from IPv4 - Stack Overflow

I’m less familiar with using an ACL (Access Control List) but my understanding is that it should help reduce the complexity that regexes introduce and makes maintenance easier.