Ruby
Print out the Regex Capture
Posted
November 05, 2007 02:08
by
DougBTX
1
2
3
4
5
6
7
regexp = Regexp.new(ARGV[0])
match_index = (ARGV[1] || 1).to_i
while line = $stdin.gets do
puts regexp.match(line.chomp)[match_index]
end
regexp = Regexp.new(ARGV[0])
match_index = (ARGV[1] || 1).to_i
while line = $stdin.gets do
puts regexp.match(line.chomp)[match_index]
end
Refactorings
No refactoring yet !
November 6, 2007,
November 06, 2007 01:48,
permalink
2 ratings.
Login to rate!
1
grep -o regexp filename
November 7, 2007,
November 07, 2007 01:49,
permalink
No rating.
Login to rate!
1
ls | grep -o "[0-9]\{1,\}"
My aim: Print out the regex capture for each line of standard input
Would rather use standard shell commands for use in bash script than going into ruby.