Update:I didn't notice my copy/paste malfunction right away. Here's the full answer.

if ( /^\w[\s]+\w/ and not /^["A pdb file"]/ )

The problem is, the square brackets create a character class: i.e., any of the characters in between them will match. Remove the square brackets (and perhaps the double quotation marks, if you do not wish to match them), and it should work:

if ( /^\w[\s]+\w/ and not /^A pdb file/ )

Your first expression matches a single word character, followed by one or more spaces, followed by another single word character (plus zero or more arbitrary characters after that.) Your intent may have been to match words of any length, in which case you would want to use \w+ instead of just \w.

You can combine those two expressions:

#!/usr/bin/env perl use 5.012; use warnings; print for grep { /^(?!A pdb file)\w+\s+\w+/ } <DATA>; __DATA__ A pdb file is on this line This line contains A pdb file A pdb file is indented too far A pdb file, but trailing spaces are here No pdb file, trailing spaces Two words and more Two wordsonly

Output:

This line contains A pdb file No pdb file, trailing spaces Two words and more Two wordsonly

Finally, it would be easier to help you if you provided some sample input and expected output; I'm guessing in most of these cases. Hopefully I got it right! See How do I post a question effectively? for some hints for the future.


In reply to Re: Match entire string, not just first character by rjt
in thread Match entire string, not just first character by SuzuBell

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.