Greetings everyone, I'm working on a Summer project and I have a little problem with my PERL code. I'm supposed to print all "ATOM" lines of a Protein PDB file and the parts I am supposed to print should not contain Hydrogen "H" atoms in the atom part, which is in between the columns 13-16. I think I got the regex for it right but it prints all the ATOM lines including ones with hydrogen atoms so I definitely got the syntax wrong. Any ideas on how to fix it ? Thanks. This is the code for printing -to a file- the ATOM lines that don't have Hydrogen
while($text =~ m/((ATOM)(\s{1,})(\d{1,})(\s{1,})(\w+)(\s{1,})[A-Z]{1,} +(\s{1,})[A-Z]{1,}(\s{1,})(\d{1,})(\s{1,})(\W+\d+.\d+)(\s{1,})(\W+\d+. +\d+)(\s{1,})(\W+\d+.\d+)(\s{1,})(\W+\d+.\d+)(\s{1,})(\d+.\d+)(\s+)([A +-Z]{1}))/gi) { print MYFILE "$1"; print MYFILE "\n"; }
And this is for printing HETATM lines that don't have HOH string and it has the same syntax with the one above, yet this works while the one at the top doesn't..
while($text =~ m/((ATOM)(\s{1,})(\d{1,})(\s{1,})(\w+)(\s{1,})[A-Z]{1,} +(\s{1,})[A-Z]{1,}(\s{1,})(\d{1,})(\s{1,})(\W+\d+.\d+)(\s{1,})(\W+\d+. +\d+)(\s{1,})(\W+\d+.\d+)(\s{1,})(\W+\d+.\d+)(\s{1,})(\d+.\d+)(\s+)([A +-Z]{1}))/gi) { print MYFILE "$1"; print MYFILE "\n"; }

In reply to Help for a regex problem ? by hellworld

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.