Reputation: 275
I am new to ruby, I am using ruby regex for puppet host based declaration, I am trying to write a regex to match servers with either web or dev or soa at end of hostname but when i tried puppet dry run i came to know that my server atl-dum-db01 is also matched in this regex. below is the output of my problem
2.1.2 :123 > "^atl-dum-web01".match(/^atl-dum-[webdevsoa\d]+/)
=> #<MatchData "atl-dum-web01">
2.1.2 :124 > "^atl-dum-db01".match(/^atl-dum-[webdevsoa\d]+/)
=> #<MatchData "atl-dum-db01">
Could someone please help me, Sorry for my bad english
Thanks in advance =)
Upvotes: 1
Views: 182
Reputation: 786261
Your use of character class is wrong. Inside character class there are no groups and every character is matched individually.
You need to use this regex for your case:
/^atl-dum-(web|dev|soa)\d+$/
Upvotes: 2