"File glob" syntax is way different from regex syntax. If you want your script to handle file-glob patterns, use "glob()" as suggested in the first reply. If you want it to support the greater expressive power of regexes, then make it clear to script users that they should specify regexes instead of file glob patterns.

A few of the more prominent differences (assuming unix/linux file systems):

magic characterregex meaningglob meaning
. match any single character match a literal period
? match zero or one occurrence of the previous character or group match any single character
* match zero or more occurrences of the previous character or group match zero or more characters
+ match one or more occurrences of the previous character or group match a literal plus-sign
^ $ anchor regex to start/end of string match literal caret/dollar-sign
( ) capture a group of characters not supported

Square-bracketed character-classes (e.g. [a-z] work the same in both, but a pattern like  [a-z]* will mean very different things for regex vs. glob.

It would be possible (probably easy and maybe even useful) to write a "glob-to-regex" converter, to produce a regex pattern that behaves the same as a given glob pattern, but if you're just looking up file names in a directory, you already have the glob() function to handle that, so why bother with the extra coding?


In reply to Re: Wildcard search in a directory by graff
in thread Wildcard search in a directory by Anonymous Monk

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.