Hello:
Looking for a suggestion of a better way to do this, instead of doing about 30 regex's in a row.
I have NWS API data for icons that references their long list of a wide array of icons with extra data that I do not need.
https://api.weather.gov/icons/land/day/tsra_sct,20/tsra_sct,40?size=me +dium https://api.weather.gov/icons/land/day/rain_showers,30/tsra_hi,30?size +=medium https://api.weather.gov/icons/land/night/rain_showers,30/rain_showers? +size=medium", https://api.weather.gov/icons/land/day/bkn?size=medium
All I really need is the modifier (tsra, rain, sleet, bkn, skc, few, ovc, etc). I don't really need anything else. Because the format somewhat changes with each response, it's a bit hard to regex down to just the modifier, as some times there are 2, and no established list of all the possibilities. At this point I figure possibly use just the first modifier listed. I am going to try and regex it down to just the modifier and see how that works, but I am afraid they will through a wrench in the works at some point that will trip up that regex.
Instead of doing a separate regex for each modifier, is there a way to use an array with a single regex to do a look up table to get the new icon reference? Or another way to see if any modifier is anywhere in the string, then return referenced new icon name?
{ 'skc' => "clear-day", 'few' => "partly-cloudy-day", 'sct' => "partly-cloudy-day", 'bkn' => "cloudy", 'wind' => "wind" }
Any suggestions would be appreciated. Once pointed in the right direction, usually I can figure the rest out. I just can't think of a better way to do this. Too many things on my mind as well, like many others right now. Thanks you!
In reply to Regex to Array lookup question by johnfl68
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |