Hi

We are using web-forms where users can configure filters for various lists of strings.

I've convinced my colleagues to use globs instead of far to powerful regexes.

For that we are using Text::Glob which is internally translating Perl's glob syntax to a regex.

But I stumbled over an incompatibility while testing with character classes provided with [...] because an unpaired [ is not masked.

Demo:

DB<84> x <[*> 0 '[KSR_3.pl' DB<85> $re = glob_to_regex( '[*' ) Unmatched [ in regex; marked by <-- HERE in m/^(?=[^\.])[ <-- HERE (?: +(?!\/).)*$/ at c:/Strawberry/perl/vendor/lib/Text/Glob.pm line 18. DB<86> x $re_str = glob_to_regex_string( '[*' ) 0 '(?=[^\\.])[(?:(?!\\/).)*' DB<87>

Point is that fileglob is automatically using the unpaired [ as a literal character, while Text::Glob is entering it as unescaped regex-meta which is causing a syntax error.

I'm not sure how to handle this best, an eval { glob_to_regex('[*') } will catch this particular input, but maybe not other broken code...

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Edge case in Text::Glob by LanX

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.