Hello, I have been working on a code for work and I found an odd glitch in my regular expression. I am looking through several blocks of texts for the Titles of some documents. The first title is "Screening Ligands by X-ray Crystallography." The text with that clearly has Screening Ligands by X-ray Crystallography in it. However, my regualr expression (below) does not pick it up. I have removed the 40 lines of code before this for brevities sake.

#!/usr/bin/perl use warnings; use strict; use feature qw(say); ... ... if ($text =~ /Screening Ligands by X ray Crystallography/) { say "MATCH!"; } else { say "NOPE!"; } }
However, if I do the code below, I do get a match.
if ($text =~ /Screening Ligands by/) { say "MATCH!"; } else { say "NOPE!"; } }
I have narrowed down the issue to the "-" I think. However, I can't search for the titles without the "-" as maybe 2/3rds of them have it. Any thoughts on how to get around this?

EDIT: Based on what you all wrote, I began looking at a few of the others that were failing and have proven its not the "-" Its still not working correctly, but I at least know its not what I thought. I may even know what the issue is, but I'll need to run some tests. I think it may be an issue from the original titles not matching what's actually in the document.


In reply to Regular Expression Hiccup by Mindsword

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.