Given the possibilities you list for an outer postcode, it can be described as:
- one or two letters
- followed by a digit
- optionally followed by a letter or digit
Which, in regex terms, is this:
[a-z]{1,2}[0-9][a-z0-9]?
... but you only want to find that pattern at the end of the URL (possibly followed by a slash), so we'll add a lookahead:
[a-z]{1,2}[0-9][a-z0-9]?(?=/?$)
The full-postcode regex in your question incorporates a number of different exclusions. For example, it looks like V, Q and X aren't allowed in some places, and there are apparently other limitations - I won't bother to try to replicate those (reading other people's regexes is never fun) ... but using what we have:
>>> import re
>>> postcode = re.compile("[a-z]{1,2}[0-9][a-z0-9]?(?=/?$)")
>>> string1= "www.xyz.com/abcdab15/"
>>> string2 = "www.xyz.com/adbdd9"
>>> re.findall(postcode, string1)
['ab15']
>>> re.findall(postcode, string2)
['dd9']