I, too, believe that what you want is a regex. I also agree with 1nickt that this isn't a code writing service. Assuming from your uncertainty that you are unfamiliar with regexes - a terrifyingly complex subject - let me try to get you started.

Character classes seem to be what you want. There are lots of resources on line, for example https://www.regular-expressions.info/charclass.html. You may or may not need different classes for each of your parts. A class for letters, digits and the other three you mention might be:

[a..z0..9'-_]

Using i after the final slash will make the regex case insensitive, meaning that you don't need to include upper case letters as well.

If you are familiar with testing, I recommend writing this as a series of tests to build up the regex one requirement at a time. Your test file will then explain to you in six months' time what you were trying to do. You won't remember otherwise. If you aren't, testing is a very useful tool to learn.

Regards,

John Davies


In reply to Re: Looking for a Regex by davies
in thread Looking for a Regex by Boberts

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.