Regex problem

I want to identify files which contain UK postcodes, which are typically of the form "FK2 8JP". My expression is:

(?#UK Postcode)\b[A-Z]{1,2}[1-9]{1,2}\s+[0-9][A-Z]{1,2}\b

That's based on .NET regex syntax, but the terms in the expression are pretty universal.

I don't see the brace repeat structure {m,n} listed in the regex help. Does Directory Opus have a limited implementation of regular expressions and, if not, why does the above expression not work?

Hello pamindic,

I'm not at all familiar with UK postcodes, so plese forgive me if I misunderstand that part of the problem.
Here in the US they are called zip codes and are 5 digit numbers followed by a - and a 4 digit number.
The 5 digit number is all that is needed, but knowing the 4 digit part can help speed delivery to inner city areas.

To start, I'll go directly to my first working answer to this problem.
Try

^[A-Z][A-Z]?[1-9][ ][0-9][A-Z][A-Z]?

It's flawed as all RegExp's are, but it is a start.

I'm still working on a reply to the remainder of your question.
I also know several other people who frequent this forum are quite good at the DOpus interpretation of RegExp's,
and my answer may soon fall.
I just wanted to be the first :laughing:

Regards,
8) Porcupine
Porcupine

Opus uses the "original" regex system by Henry Spencer, which doesn't support things like this unfortunately.

We'll probably shift to a more modern regex in the next version.

The problem with regexps is there are so many "standards" to choose from. I think every program and language I use that supports regexps has a slightly different syntax or set of features that I have to remember. :frowning: In TextPad you have to escape brackets etc. to make them work while in everything else you escape them to make them into normal characters... Sometimes I forget and spend ages wondering why stuff isn't working.

Regexps are limited anyway. I want to be able to parse text using function calls into a scripting language. :slight_smile: :slight_smile: :slight_smile:

PS: Porc's regexp for UK postcosts looks good to me.

That was quick! Thanks to all for your replies.