... the format somewhat changes with each response ... no established list of all the possibilities. ... they will through a wrench in the works ...

Kinda hard to do pattern matching when there's no pattern. :) Maybe something like the following. Also, please see How to ask better questions using Test::More and sample data and Short, Self-Contained, Correct Example for useful ways of asking questions — both of the monks and of yourself! (Update: Also also, see haukex's Building Regex Alternations Dynamically article for a discussion of building the  $rx_modifier regex.)

c:\@Work\Perl\monks>perl use strict; use warnings; use Test::More 'no_plan'; use Test::NoWarnings; my @Tests = ( [ 'https://api.weather.gov/icons/land/day/tsra_sct,20/tsra_sct,40?si +ze=medium', 'tsra', 'tsra', ], [ 'https://api.weather.gov/icons/land/day/rain_showers,30/tsra_hi,30 +?size=medium', 'rain', 'tsra', ], [ 'https://api.weather.gov/icons/land/night/rain_showers,30/rain_sho +wers?size=medium', 'rain', 'rain', ], [ 'https://api.weather.gov/icons/land/day/bkn?size=medium', 'bkn', ] +, [ 'https://api.weather.gov/icons/land/day/size=medium', ], ); my $rx_pre = qr{ (?<= /) }xms; my $rx_post = qr{ (?= [_?]) }xms; my $rx_generic_modifier = qr{ [[:lower:]]+ }xms; my @modifiers = qw(tsra rain sleet bkn skc few ovc); my ($rx_modifier) = map qr{ $rx_pre (?: $_ | $rx_generic_modifier) $rx_post }xms, join '|', map quotemeta, reverse sort @modifiers ; # print "modifiers regex: $rx_modifier \n"; # for debug VECTOR: for my $ar_vector (@Tests) { if (not ref $ar_vector) { note $ar_vector; next VECTOR; } my ($string, @expected_modifiers) = @$ar_vector; my @got_modifiers = $string =~ m{ $rx_modifier }xmsg; is_deeply \@got_modifiers, \@expected_modifiers, "'$string' -> (@got_modifiers)" ; } # end for VECTOR done_testing; __END__ ok 1 - 'https://api.weather.gov/icons/land/day/tsra_sct,20/tsra_sct,40 +?size=medium' -> (tsra tsra) ok 2 - 'https://api.weather.gov/icons/land/day/rain_showers,30/tsra_hi +,30?size=medium' -> (rain tsra) ok 3 - 'https://api.weather.gov/icons/land/night/rain_showers,30/rain_ +showers?size=medium' -> (rain rain) ok 4 - 'https://api.weather.gov/icons/land/day/bkn?size=medium' -> (bk +n) ok 5 - 'https://api.weather.gov/icons/land/day/size=medium' -> () 1..5 ok 6 - no warnings 1..6

Update: Moved link to haukex's article into lexical contiguity with other documentation links.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Regex to Array lookup question by AnomalousMonk
in thread Regex to Array lookup question by johnfl68

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.