简体   繁体   中英

how to get exact string match for multiple string in ruby

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 =)

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+$/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM