I'm taking a guess here, but a quick check of the regex pattern syntax for the TR1" expressions (following the Google trail from the "wregex" keyword - I hope it led to a relevant topic) shows that it does not support the named matching groups syntax that you have used (it works with the .NET regex syntax). I would suggest that you can probably get it to at least be accepted if you remove the '(?<x>' structures (remember to keep the '(' part as it marks the beginning of the group definition).
However this also makes it a little harder to retrieve the information that is captured by the pattern. One advantage of named capture groups is that they generally allow access to multiple groups that share the same name. In other words, that pattern contains several groups that are called "d" - you can retrieve the captured characters by requesting the "d" capture no matter which one actually did the work. However if you only have numbered groups, then you need to check each possible group number to see which actually made the match.
On the other hand, if all you are looking for is a "yes/no" validation, then you don't really care about extracting the individual parts so this is not a problem.
The second pattern would seem to be overly complex in that it uses lots of character class definitions just to allow for case insensitive matches - instead you can use the "case insensitive" match (I think the "regex_constants::icase" is appropriate in your case but no guarantee). Therefore sequences such as:
can be replaced by:
as long as you have the "case insensitive" match option set.
I have no idea of what the "rules" are as to what makes up a valid UK postcode and so I can't comment on the correctness of the pattern. However, from what I can see, at a top level there are 5 basic alternatives. 4 of those seem to be specific letter combinations such as "GIR 0AA' and "SAN TA1".
Looking at the first major alternative, it can be broken down something like:
Therefore the "S" will match the first character set definition. The next part of the pattern is 3 alternatives: the first can't match as it is 2 digits and the last can't match as it requires 1 leading digit. The middle alternative is itself 2 alternatives but can be re-written from
All I have done is to factor out the initial parts of each alternative (which are the same) and make the remaining pattern of the 2nd alternative optional.
From this we can see that the "W" will match the initial character set definition.
Now we get to the problem part. The character after the "W" is "I" but the pattern requires that it be a digit. Therefore your text will fail to match the pattern.
I have no idea what the rules are to allow a valid UK postcode so I can't say how to fix this.