You are viewing limited content. For full access, please sign in.

Question

Question

What to do if array item is not found from Split

asked on November 7, 2016 Show version history

I have a value such as "xxxxx - 123456".  In workflow, I want to extract out the number from this string.  I am using a Token Calculator activity with a function of "IF(FIND("-", %(Entry Name)) = -1, 0, NUMBERVALUE(CHOOSEA(2,SPLIT(%(Entry Name),"-"))))"  The problem is if the string is not formatted correctly where the dash does not exist, then a second entry does not exist and an exception occurs.  I was expecting it to just return a 0 since the FIND should return -1.

 

What is the easiest way to resolve this issue?

0 0

Answer

SELECTED ANSWER
replied on November 7, 2016

That's because parentheses indicate match groups and you only want to use those around data you'd like extracted. You can use \s-\s(\d{5,6}) or just (\d{5,6}). If you want to make absolutely sure you wouldn't accidentally get a group of 5 digits from the first group, you can go with (\d{5,6})$ (where $ indicates the end of the input).

2 0

Replies

replied on November 7, 2016 Show version history

Have you tried using a Reg Expression on your Token instead to just pull the first 5 numbers, it can provide more flexibility in providing options

Right Click on the Token Field and Select Token Editor in the Drop Down

Add a Regular Expression in the Token Editor, what appears between the {} is how many digits to capture in the token \d{5} means to fidn the first 5 digits together so leading spaces and where the dash is is not important

You can have one Token for the first set and another for the Second set of numbers such as \d{5}\s*?-?\s*?(\d{5}) which would find the second set of 5 digits in any of these conditions

12345 -    67890
1234567890
12345 -67890
12345- 67890
12345-67890

 

1 0
replied on November 7, 2016

I am not very good at regular expressions.  What would the regular expression look like to find all digits after a dash?

0 0
replied on November 7, 2016

If you could provide some samples of what the number variations could look like, can help you with that. With Reg expressions its sometimes best to understand the whole scheme such as it 5 numbers then a dash and 6 numbers.

0 0
replied on November 7, 2016

It will always look like this...

"xxxxxx - ddddd" where "xxxxxx" is a combination of letters and numbers and is an unknown length, then a space / dash / space, then either 5 or 6 digits.  All I want to capture is the 5 or 6 digits at the end (after the space / dash / space)

 

So far I have this ... (\s-\s)(\d{5,6})  but this wants to include the space / dash / space in the match and I only want the digits after that.

0 0
SELECTED ANSWER
replied on November 7, 2016

That's because parentheses indicate match groups and you only want to use those around data you'd like extracted. You can use \s-\s(\d{5,6}) or just (\d{5,6}). If you want to make absolutely sure you wouldn't accidentally get a group of 5 digits from the first group, you can go with (\d{5,6})$ (where $ indicates the end of the input).

2 0
replied on November 8, 2016

Thanks, the "(\d{5,6})$" is what I needed.

0 0
replied on November 7, 2016

Depending on whether you're trying to also enforce that format on the incoming values, it might be easier to use the token functions together with indexes:

Splitting it on " - " will give you a multi-value token, then you just take the second part. If the value doesn't have a dash, you'd only get a single-value token, but Workflow defaults to returning the last value when you're request an index past the available values (so in this case the "last" value would be the first and only value and you'd get your input back unmodified).

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.