Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
JM39
Creator
Creator

How to look for data in a particular format

Hello.  I have some address data and I'd like to derive the country based on whether there's a UK postcode in the data.  So if the value in the postcode column is one of these formats then I want to assume that the country is UK

An nAA

Ann nAA

AAn nAA

AAnn nAA

AnA nAA

AAnA nAA

 

A=Alpha character

n=numeric character

Is it possible to do that in tMap?

 

Thank you!

Labels (2)
1 Solution

Accepted Solutions
akumar2301
Specialist II
Specialist II

you might have postcode null in input

 

try 

(row1.Postcode != null) && row1.Postcode.matches ("^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$") ? "GB" : null

View solution in original post

4 Replies
akumar2301
Specialist II
Specialist II

To check uk postal code format. There is a regex

https://howtodoinjava.com/regex/uk-postcode-validation/
JM39
Creator
Creator
Author

That's really helpful, thank you.  But how would I put this into the tMap expression?  I tried this:

 

row1.Postcode.matches ("^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$") ? "GB" : null

 

So I'm saying if the postcode matches the pattern, then set the value to GB, else null but it doesn't seem to like that.  It produces a java.lang.NullPointerException error.

akumar2301
Specialist II
Specialist II

you might have postcode null in input

 

try 

(row1.Postcode != null) && row1.Postcode.matches ("^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$") ? "GB" : null

JM39
Creator
Creator
Author

Perfect, that worked thanks!