simple code

A

angel.of.north

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
 
W

William James

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
 
W

William James

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

#!awk -f

BEGIN {
print " {| class=\"wikitable\"\
|-\
Table -- put your title here\
|-" }

/[ \t]+[A-Z]/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top