I have some text blocks like
John+and+Co-Accountants-Hove-BN31GE-2959519
I need a function to extract the postcode \"BN31GE\". It may happen to not exist
Use a regex: preg_grep function,
I don't know the format of english postcodes but you could go with something like:
(-[a-zA-Z0-9]+-)+
This matches
You can then proceed at taking always the second value or you can enhance you regex to match exactly english postcodes, something like maybe
([A-Z0-9]{6})