Split UK postcode into two main parts using java?

In java this would be: String fields = postcode. Split("\\s") where postcode is a validated postcode and fields will be an array of length 2 containing the first and second parts Edit: If this is to validate user input, and you want to validate the first part, your regex would be: Pattern firstPart = Pattern. Compile("A-Z{1,2}0-9R0-9A-Z?

") To validate the second part it is: Pattern secondPart = Pattern. Compile("0-9A-Z-CIKMOV{2}").

In java this would be: String fields = postcode. Split("\\s"); where postcode is a validated postcode and fields will be an array of length 2 containing the first and second parts. Edit: If this is to validate user input, and you want to validate the first part, your regex would be: Pattern firstPart = Pattern.

Compile("A-Z{1,2}0-9R0-9A-Z?"); To validate the second part it is: Pattern secondPart = Pattern. Compile("0-9A-Z-CIKMOV{2}").

I think he's asking about the case when it's not separated by a space. The rules to do it in that case seem fairly complicated. – Pekka Apr 10 at 10:52 @Pekka - a postcode with no space will fail validation.

Perhaps I misunderstand, but I though the OP wanted to split validated addresses? – Richard H Apr 10 at 10:53 @Richard yeah, the OP needs to clarify. Check out the Wikipedia link above, maybe he needs all separate components.

– Pekka Apr 10 at 10:55 I just need the two main parts but want to cover for cases where spaces have not being entered which is handled by the above regex for validation – Farouk Alhassan Apr 10 at 10:56 1 In that case, without looking at this more closely for a more elegant approach, you may have to check 7 different regex matches for each postcode. – Richard H Apr 10 at 11:02.

You can use the Google's recentlly open sourced library for this. code.google.com/p/libphonenumber.

Where postcode is a validated postcode and fields will be an array of length 2 containing the first and second parts.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions