I need to parse a csv file to grab some infos from each row ( Company code, Company description, Country), I'm using preg_match in PHP to parse the file but I got in trouble with some rows.
Below some rows of the csv file
"ASTA","Aerospace Technologies of Australia Pty Ltd (Australia)"
"ATAC"," American Tactical Aircraft Consultants (United States)"
"ATEC"," ATEC vos (Czech Republic)"
"ATG","Aviation Technology Group Inc (United States)"
"ATLAS","Atlas Aircraft Corporation of South Africa (Pty) Ltd (South Africa)"
"ATR","GIE Avions de Transport Régional (France/Italy)"
"AUSTER","Auster Aircraft Ltd (United Kingdom)"
"AUSTFLIGHT","Austflight ULA Pty Ltd (Australia)"
"AUSTRALIAN AEROSPACE","Australian Aerospace Pty Ltd (Australia)"
"AUSTRALITE","Australite Inc (United States)"
"AUTOGYRO","AutoGyro Europe GmbH (Germany)"
"AVANTAGE","OOO Samoletstroitelynyi Kompaniya Avantazh (Russia)"
"AVCRAFT","AvCraft Aviation LLC (United States)"
"AVEKO","Aveko sro (Czech Republic)"
"AVIA (1)","Azionari Vercellese Industrie Aeronautiche (Italy)"
"AVIA (2)","Avia-Zavody Jirího Dimitrova (Czech Republic)"
The PHP preg_match code is the following
preg_match('#^(.+?)\s\((.+?)\)$#',$string,$matches);
The code works fine with rows like the following one:
"ASSO AEREI","Asso Aerei Srl (Italy)"
In the example above I succesfully get the three datas into matches array...but with the following row
"ATLAS","Atlas Aircraft Corporation of South Africa (Pty) Ltd (South Africa)"
I get, as Company Description:
Atlas Aircraft Corporation of South Africa
and as Country:
Pty) Ltd (South Africa
They should be, instead:
Atlas Aircraft Corporation of South Africa (Pty) Ltd
and
South Africa
One more issue that is getting me crazy is: when the rows doesn't include a country, like the following row
"AERFER-AERMACCHI","see AERFER and AERMACCHI"
I get an empty Company description array.
Any help to fix the regex pattern? Yhanks a lot for any help