(see the updates I've made to the OP)

Sure, the ugly code produces the output I want -- that the supplied category (albeit, with an additional trailing dot), which comes from the list of possible categories, does match the category in the record (again, doctored with a trailing dot), when considering the 'level of matching' required.

Although it's not my current application, perhaps think of the number of postings in the Usenet hierarchies. The data might be:

comp.lang.c,100
comp.lang.beta,23
comp.lang.java.help,123
comp.object,12
alt.3d,12
alt.animals.llama,1423
...

The types of question I'm looking to answer:

"How many postings are there in the 'comp' hierarchy and below?"

For this question, we can say:

Matches: comp, comp.lang, comp.lang.c... (the group names all start with 'comp')

Do not Match: alt, alt.3d, alt.animals.llama... (the group names do not start with 'comp')

"How many postings are there in the 'alt.*' hierarchy and below?"

For this question, we can say:

Matches: alt.3d, alt.animals.llama... (the group names all start with 'alt.{something}' and {something} is non-null)

Do not match: alt, comp, comp.lang.c... (the group names do NOT start with 'alt.{something}' and {something} is non-null)

Conceptually, it's such a simple thing: "Does RECORD CAT start with the TEST string?" ...

TEST         RECORD          MATCHES?

comp         comp.lang       Yes
comp         comp            Yes
comp         comp.hw         No

comp.lang    comp            No
comp.lang    comp.lang       Yes
comp.lang    comp.lang.c     Yes
comp.lang    comp.lang.c++   Yes
comp.lang    alt             No
comp.lang    alt.test        No

This is why I was thinking there must be a simple regex thing to say "give me the first 2 items from the category string" (using parentheses and a dot or end-of-string as the separator - 'comp.lang') and I'll compare that to the start of the record string (in a simple regex: /^$rec_string\.*$/ or something).....

...shaking his head in bewilderment...


In reply to Re^3: I think regex Should Help Here... but How!? by ozboomer
in thread I think regex Should Help Here... but How!? by ozboomer

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.