Forum: Rails France Regex Problem

1943caab378a3aaa894384eac6cec745?d=identicon&s=25 Cyril J. (cyril_j)
on 2011-09-09 16:41
I have a regex problem. I am trying to match this string : >1_4_138_F3

Here is my code:


if f3_entry =~ /(\^>*\_*\_*\_F3)/
  f3_out.puts f3_entry
end

Not exactly sure if I am in the right direction or not, but I want to
use the underscore as the matching point, while anything can be between
the underscores. Can anyone point me in the right direction?

- C
Ba6ad1ba69120a459cfe2f60e0fac559?d=identicon&s=25 Azuma -01 (azuma-01)
on 2011-11-03 17:35
your regex should be more like this:
  /^(>\d+_\d+_\d+_F3)/

so $1 (variable where the frist match is stored), when maching with
those string
  ">1_4_138_F3: rest of the line"
  ">55_1087_98_F3 rest of the line"
will respectively return
  ">1_4_138_F3"
  ">55_1087_98_F3"

if the string most only be like ">1_4_138_F3" add the symbol '$' at the
end of the regex (/^(>\d+_\d+_\d+_F3)$/)

hope this helps
This topic is locked and can not be replied to.