regular expression
-
hi, i have a space seperated list of codes and the corresponding regions and countries. it looks like this AAA kairo, Egypt BBB Region, Country. i want to extract alll the information (code, region and country) from that file with a regular (if possible only one with subpatterns)expression. is it possible to make a regular expression that returns me an array that looks like this: Array(0=>Array("code","region","country"), 1=>Array(blabla)), or an associative array. can anyone please help. thanks
-
hi, i have a space seperated list of codes and the corresponding regions and countries. it looks like this AAA kairo, Egypt BBB Region, Country. i want to extract alll the information (code, region and country) from that file with a regular (if possible only one with subpatterns)expression. is it possible to make a regular expression that returns me an array that looks like this: Array(0=>Array("code","region","country"), 1=>Array(blabla)), or an associative array. can anyone please help. thanks
([A-Z]{3})\s+([\w|\s]+)\,\s*([\w|\s]+)
Should work based on the data you supplied, the first group looks for exactly three characters (from A to Z), then some whitespace. The second group looks for word characters or whitespace in sequence until it hits a comma. The third group looks for word characters or whitespace until it hits the end of line.