RegEx Help in Ruby
Posted
by Akash
on Stack Overflow
See other posts from Stack Overflow
or by Akash
Published on 2010-05-19T01:47:47Z
Indexed on
2010/05/19
1:50 UTC
Read the original article
Hit count: 425
My sample file is like below:
H343423 Something1 Something2
C343423 0
A23423432 asdfasdf sdfs
#2342323
I have the following regex:
if (line =~ /^[HC]\d+\s/) != nil
puts line
end
Basically I want to read everything that starts with H or C and is followed by numbers and I want to stop reading when space is encountered (I want to read one word).
Output I want is:
H343423
C343423
Output my RegEx is getting is:
H343423 Something1 Something2
C343423 0
So it is fetching the whole line but I just want it to stop after first word is read.
Any help?
© Stack Overflow or respective owner