[resolved] Using TMap to parse complex string

One Star

[resolved] Using TMap to parse complex string

I am new to TOS and to Java, so I am having a hard time figuring out how to parse out a string in TMap. I have a number of string columns in the input to the Tmap that should have a length of 5 be all numeric (e.g., '10101'). Unfortunately, sprinkled into columns are values like '3100'. The output still needs to have 5 columns, but the second column should have the value of ''. any ideas on how I can test for a non-numeric value and then take 3 characters for the column vs. using only 1 character?
Thanks, John

Accepted Solutions
One Star

Re: [resolved] Using TMap to parse complex string

Andrew,
Thanks for your help, especially the link to the Regex validation tool. I have not used Regex before, so it took a lot of experimenting to get just the expression just right. I am using tExtractRegexFields to parse my string into individual columns using the followng expression:
"(|\\\\]|\"|\\*)(|\\\\]|\"|\\*)(|\\\\]|\"|\\*)(|\\\\]|\"|\\*)(|\\\\]|\"|\\*)(|\\\\]|\"|\\*)"
John

All Replies
One Star

Re: [resolved] Using TMap to parse complex string

I am new to TOS and to Java, so I am having a hard time figuring out how to parse out a string in TMap...
The output still needs to have 5 columns, but the second column should have the value of ''. any ideas on how I can test for a non-numeric value and then take 3 characters for the column vs. using only 1 character?
Thanks, John

This sounds like a job for a regular expression!
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
The Java reference is your friend. It has all the information you're looking for and more! If you've dealt with programming in other languages you may have dealt with some flavor of RegEx functionality. The below code snippet will match a single "value", being defined as a single digit optionally enclosed in square brackets. This wouldn't work if the number in the brackets could be several digits long - for instance, if "0110" is valid input, but it should be a good starting point.
There is an online tool for testing how given input strings would be parsed given a RegEx at http://www.fileformat.info/tool/regex.htm
Good Luck!
Pattern.compile("(\\?)+?")
One Star

Re: [resolved] Using TMap to parse complex string

Andrew,
Thanks for your help, especially the link to the Regex validation tool. I have not used Regex before, so it took a lot of experimenting to get just the expression just right. I am using tExtractRegexFields to parse my string into individual columns using the followng expression:
"(|\\\\]|\"|\\*)(|\\\\]|\"|\\*)(|\\\\]|\"|\\*)(|\\\\]|\"|\\*)(|\\\\]|\"|\\*)(|\\\\]|\"|\\*)"
John