Again, I have some code that works but I'm sure it could be better written using a regex that I don't know how to write. My code is:

$sTest = uc($sTest); if (uc($sLine) eq "REM $sTest" || Left(uc($sLine), 5 + length($sTest)) + eq "REM $sTest ") {

Left is a sub I have written to help me until I get out of the habit of writing VBA instead of Perl. It's a very basic call to substr.

I have been trying to write something along the lines of:

if ($sLine =~ m/rem $sTest€/i) {

The problem I have is replacing the with something that means "a space or the end of the string". I'm not sure whether Corion is hinting at how to do this in Re: Regex - Matching prefixes of a word or whether it means "one or the other, but not both in a single construct". Either way, that is the closest my searching has come to an answer. Is there a better one, please?

TIA & Regards,

John Davies


In reply to Space or end of string in regex by davies

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.