Trevor Morrison wrote: > HI, > > I am trying to use regex to extract the city,state and zip out of a file. > Now, the problem is the city can have more then one word to it like > > San Antonio > > San Francisco > > etc, > > I have also, bumped into case of 4 or 5 words in the city name! I am > looking for a regex expression that will take this into account knowing > that the form of the line is: > > city[space]state(2 letters)[space] zip (could be 5 or 9 digits) > > An example: > > Loves Park IL 61111 > or > APO AE NY 09012 > or > St. George UT 84770 > or > Columbus OH 43202 > or > Salt Lake City UT 84118 > > > TIA > > Trevor
try: #!/usr/bin/perl -w use strict; while(<>){ chomp; my($city,$state,$zip) = /(.+)\s+(\S+)\s+(\S+)/; print pack("A7","city:"),$city,"\n"; print pack("A7","State:"),$state,"\n"; print pack("A7","Zip:"),$zip,"\n"; } __END__ it doesn't really meet your "requirement" since it also matches: Salt Lake City Ut. 84118-12345 but you might consider that to be a valid US address. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]