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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |