Search code examples
regexrabbitmqpolicy

How to set multiple patterns in RabbitMQ policy


I am trying to create a new policy matching multiple patterns in RabbitMQ. However, the below options are not working. Please suggest the correct way of setting multiple patterns in RabbitMQ.

Need to expire queues(after certain period of time) matching names test., Test., TEST.*

Patterns not working,

  1. I tried using the policy Message TTL and pattern as test.*, Test.*, TEST.*
  2. I also tried /G[test].*/i ==> Case insensitive regex

Below works,

  1. Only if I set individual policies for test.* or TEST.*, rabbitmq recognizes.

Below is the master set of queue names that I expect the regex to match,

Service-ManualTest
TEST.service.mail
TESTCreateQueue
Test reindex            
Test.profile.queue      
Testing.service.results     
My_TestQueue    
status.queue.test   
test myQueue
testbulkupload.auto.manual
testreportqueue

Solution

    • Using pattern test.*, Test.*, TEST.* will match a string that matches for example this string test, Test, TEST containing 3 times the word test.

    • Using pattern G[test].* (which can be written as G[tse].*) will match for example Gt or Gs optionally followed by any character.

      For example in Javascript, the format of / at the start and end are the delimiters and the /i is the case insensitive flag.

    If you only want to match all 3 variations of test, you can use this pattern without the .*

    (?:[Tt]est|TEST)
    

    If an inline modifier is supported, you can get a case insensitive match using (?i)test.* or a verbose version listing all the options using character classes [Tt][Ee][Ss][Tt].*