Rather than use regex directly, you could use an AppleScript that employs NSDataDetector (which I believe uses regexes under the hood anyway) to extract the address.
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
on extractAddressFrom:theString
set dataDetector to current application's NSDataDetector's dataDetectorWithTypes:(current application's NSTextCheckingTypeAddress) |error|:(missing value)
set addresses to dataDetector's matchesInString:theString options:0 range:{location:0, |length|:length of theString}
return (addresses's valueForKeyPath:"components") as record
end extractAddressFrom:
on makeKMDictionary:theRecord withName:theName
set dict to current application's NSDictionary's dictionaryWithDictionary:theRecord
set allKeys to dict's allKeys()
tell application "Keyboard Maestro Engine"
set newDict to make new dictionary with properties {name:theName}
repeat with theKey in allKeys
set theValue to (dict's valueForKey:theKey) as text
set kmKey to (theKey as text)
tell newDict to make new dictionary key with properties {name:kmKey, value:theValue}
end repeat
end tell
end makeKMDictionary:withName:
on run
tell application "Keyboard Maestro Engine"
set addressBlock to getvariable "AddressBlock"
end tell
-- set addressBlock to "11401 NW 12th St
--Miami, FL 33172"
set addressFields to my extractAddressFrom:addressBlock
my makeKMDictionary:addressFields withName:"AddressFields"
end run
Put this script into an Execute an AppleScript action and it will return a KM dictionary containing the different address fields.
If you'd prefer an approach that doesn't involve AppleScript then here's one based entirely on native KM actions. Just make sure you've copied the address into the clipboard before running the macro.