You're confusing wildcards with regular expressions.

With wildcards, * is definitely "zero or more of any possible character including the space."

With regular expressions, * is "zero or more of the last token"

Your last token before the * is [A-Z]; hence, you'r [A-Z]*.pdf matches things like:

...but not something like file.pdf, for instance.

So regarding your regex, what you really wanted was [A-Z].*\.pdf... you see, a "." means (in Perl's regular expressions), "any single character except for the newline." (this is also why you have to escape the following dot, the one separating the filename from the extension)

Also, your right-hand side of the substitution won't work... that's going to name the file, literally, [A-Z]*

Instead, you have to capture the filename in a special variable (with brackets) and use that variable (in this case it's going to be $1, because it's going to be the first bracket counting from the left). You do it like this:

s/([A-Z].*)\.pdf/$1/;

There. Your filename, without the extension.

frodo72's solution is, however, better (and there are others, of course), but this is what you were trying to do, corrected.


In reply to Re: using s/// to remove file extensions by cog
in thread using s/// to remove file extensions by Plotinus

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.