Regex Problem

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

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

your regex should be more like this:

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

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