From: William James Date: 2007-10-20T10:20:02+09:00 Subject: Re: simple code On Oct 19, 8:44 am, "angel.of.no...@googlemail.com" wrote: > hi > > #!/usr/bin/ruby -w > re=Regexp.new('\s+[A-Z]') > puts " {| class=\"wikitable\" > |- > Table -- put your title here > |-" > while line = gets > md=re.match(line) > if md =~ nil > else > puts md > end > end > > I input the text as > > COM - Commercial > EDU - Educational > GOV - Povernment > NET - Network > MIL - Military > ORG - Non-profit organisations > > and I get the result as > > {| class="wikitable" > |- > Table -- put your title here > |- > nil > C > E > G > N > M > O > nil > > How do I prevent the nil appearing? > How do I access each matchdata with the postmatchdata on each line? > > DavidR re = /\s+[A-Z]/ puts ' {| class="wikitable" |- Table -- put your title here |-' while line = gets puts line if line =~ re end