0

I need help with regular expressions. I have some queues in the rabbitMQ, about 1000:

ha-collector-data-test2
ha-collector-data-1434
ha-collector-data-45-test3
ha-collector-data-terty4
ha-collector-data-341
etc.

And I need to filter these queues. For example:

FILTER='[{"name": "ha-collector-data-test2"}, {"name": "ha-collector-data-1434"}, {"name": "ha-collector-data-45-test3"}, {"name": "ha-collector-data-terty4"} ]'

To describe every queue by a separate name is difficult

Which regular expression should I use for my queues which have same start names? I used this but it is wrong:

FILTER='[{"name": "ha-collector-data-*"} ]'
FILTER='[{"name": "ha-collector-data-[a-z]"} ]'
perrfect
  • 65
  • 1
  • 7
  • 1
    I suggest using a site like https://regex101.com to test, observe and learn how the regex matching is (not) being performed. – parkamark Feb 13 '20 at 08:47

1 Answers1

0

The following pattern should match your examples:

FILTER='[{"name": "ha-collector-data-.*"} ]'

This specifies: Match every character (= '.') zero or more times (= '*')

Your both filters dont work because:

1) FILTER='[{"name": "ha-collector-data-*"} ]'
'*' matches the preceding character zero or more times. Since the preceding char is - 
this rule matches something like ha-collector-data-- 


2) FILTER='[{"name": "ha-collector-data-[a-z]"} ]'
This filter doesn't match the strings that start with numbers after '-' and 
furthermore it matches the next char only.
Lorem ipsum
  • 892
  • 5
  • 15