Forum: Rails France Regex Problem

Posted by 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
Posted by 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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.