Hello Monks, I once again come seeking your wisdom -- I have an array of regex patterns that I would like to match on but my current code block seems to only match once and stop, but the string has most matches within it...

my $devicesData = '"deviceId": 6931162, "friendlyName": "U12H240T70 - R6300v2", "lastInform": "2016-02-15T15:08:24.611Z", "sn": "4401487KA0276", "subscriberCode": "8245112910034496"'; my @matches = ( qr/"sn": "(.+?)"/, qr/"subscriberCode": "(.+?)"/, qr/"friendlyName": "(.+?)"/, qr/"SolicitTimestamp": "(.+?)"/, qr/"StatusCode": "(.+?)"/, ); if ($devicesData ~~ @matches) { print "Found: $1\n"; } #output Found: 4401487KA0276

With this method, is it possible to match on each pattern? I feel like I'm missing a regex operator to continue to check matches - I tried using the g modifier and join | to each element but to no avail -- Additionally, I went this route vs having 5 separate regex calls with each pattern so that if this scripts needs to grow, I can simply add the pattern to the match array and be flexible as the data could change at some point! Always, greatly appreciate the direction!


In reply to Regex Array matching by Monkless

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.