in reply to Matching dialplan rules...

It's not clear by the rules, but your examples suggest: Taking the above into account, I'd use:
qr { ^ # Anchor at the start _? # Optional underscore [\#*]* # Optional sharps and stars # Numerical part: [0-9]+ # Digits (?: # Optional \[\s*[0-9]+-[0-9]\] # '[', whitespace, digits, '-', dig +it, ']' )? # End optional [\#*]* # Optional sharps and stars # Character part: X* # Zero or more 'X' (?: # Optional # Either !X* # '!' followed by 'X's, (?:\.X*)? # optionally '.' followed by 'X' +s | # or \.X* # '.' followed by 'X's, (?:!X*)? # optionally '!' followed by 'X' +s )? # End optional $ # Anchor at the end. }x;
I only briefly tested it, but it does match your examples.