Words[0] ! =~ /#*/ doesn't match "#aaaaaaaaa"

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

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?

/#/ will match any string (the '’ makes ‘#’ optional)
/#/ (or /#+/) will match strings containing a ‘#’
/^#/ (or /^#+/) will match strings starting with a ‘#’

Rick

···


http://www.rickbradley.com MUPRN: 579 (79F/83F)
> recently as well.
random email haiku | this makes things interesting but
> not overly so.

Use /^#/ and not /#*/ -- these are regular expressions, not
globbing or shell wildmat ...

-- Dossy

···

On 2002.06.08, Peter Booth <pbooth@nocoincidences.com> 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

--
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)

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

···

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

For easier reading of the code I suggest doing like the following

IO.foreach(…) do line
next if line =~ /^#/

    do_the_rest

end

Then you can ignore the #-lines in every line of code after the first
line.

/Erik

···

On Sat, 2002-06-08 at 05:57, Peter Booth 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]


Erik Bågfors | erik@bagfors.nu
Supporter of free software | GSM +46 733 279 273
fingerprint: 6666 A85B 95D3 D26B 296B 6C60 4F32 2C0B 693D 6E32