From: Holden Glova Date: 2002-06-08T13:29:07+09:00 Subject: Re: words[0] ! =~ /#*/ doesn't match "#aaaaaaaaa" -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, 08 Jun 2002 15:57, you wrote: > I am attempting to parse the following file and ignore lines that begin > with a # > but my regexp doesn't seem to match correctly. Can anyone tell me the > "right" way > to match a string that begins with a # character? > > Peter Booth > > > IO.foreach("C:/apps/workspace/web/build/zoneinfo.db") do |line| > words = line.split("|") > if words.length == 3 && words[0] != "realm" && words[0] ! =~ /#*/ > realm, zone, hostlist = words[0], words[1], words[2] > > > > qatest|dmz|nbigqsa02 > qatest|ndmz|nmigqsa06 > #qatest|tools|nycmqsa01,nycmqsa02 > #qatest|ficc|nwwpqsa01 Maybe this helps, you are looking for "does not match" irb(main):001:0> a = ['qatest|dmz|nbigqsa02', 'qatest|ndmz|nmigqsa06', '#qatest|tools|nycmqsa01,nycmqsa02', '#qatest|ficc|nwwpqsa01'] ["qatest|dmz|nbigqsa02", "qatest|ndmz|nmigqsa06", "#qatest|tools|nycmqsa01,nycmqsa02", "#qatest|ficc|nwwpqsa01"] irb(main):011:0> a.each do |line| irb(main):012:1* words = line.split('|') irb(main):013:1> if words.length == 3 && words[0] != 'realm' && words[0] !~ /^#/ irb(main):014:2> realm, zone, host_list = words[0], words[1], words[2] irb(main):015:2> puts "#{realm} #{zone} #{host_list}" irb(main):016:2> end irb(main):017:1> end qatest dmz nbigqsa02 qatest ndmz nmigqsa06 - -- Signed, Holden Glova -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9AYaE0X8w8X71zPcRAi6iAJ4ypt6bONk5CJcku9L2dMWm0waUAQCdFbYS FAvpv9glIA0HpIQKFH3c3As= =v5Qj -----END PGP SIGNATURE-----