You create a user defined function - as long as the potential zip code is enclosed by space or is in the last token position this should work
drop function if exists tokens;
delimiter //
create function tokens(instring varchar(255))
returns varchar(255)
begin
declare tempstring varchar(100);
declare outstring varchar(100);
declare checkit int;
set tempstring = ltrim(rtrim(instring));
set checkit = 0;
looper: while tempstring is not null and instr(tempstring,' ') > 0 do
set outstring = substr(tempstring,1,instr(tempstring, ' ') - 1);
set tempstring = ltrim(rtrim(replace(tempstring,outstring,'')));
if length(outstring) = 5 then
if substring(outstring,1,1) between char(48) and char(57) and
substring(outstring,2,1) between char(48) and char(57) and
substring(outstring,3,1) between char(48) and char(57) and
substring(outstring,4,1) between char(48) and char(57) and
substring(outstring,5,1) between char(48) and char(57) then
set checkit = 1;
leave looper;
end if;
end if;
end while;
if checkit = 0 then
set outstring = tempstring;
if length(outstring) = 5 then
if substring(outstring,1,1) between char(48) and char(57) and
substring(outstring,2,1) between char(48) and char(57) and
substring(outstring,3,1) between char(48) and char(57) and
substring(outstring,4,1) between char(48) and char(57) and
substring(outstring,5,1) between char(48) and char(57) then
set checkit = 1;
end if;
end if;
end if;
if checkit = 0 then set outstring = 'NotFound'; end if;
return outstring;
end //
delimiter ;
and given this
+------+---------------------+
| id | address |
+------+---------------------+
| 1 | 13 mont 12c45 st |
| 2 | 13 mont 12345 st |
| 3 | 13 mont 12c45 45678 |
| 4 | 56789 mont 12c45 st |
+------+---------------------+
Function returns this
+------+---------------------+----------+
| id | address | zipcode |
+------+---------------------+----------+
| 1 | 13 mont 12c45 st | NotFound |
| 2 | 13 mont 12345 st | 12345 |
| 3 | 13 mont 12c45 45678 | 45678 |
| 4 | 56789 mont 12c45 st | 56789 |
+------+---------------------+----------+
INSTRsupports regex. Can you show use a sample which you are trying to extract?