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

Question

Question

Regular Expression Result Value Changes When Alpha Character is added after number?

asked on March 4, 2014

Here is what I'm trying to do.

I have Business License records that I'd like to file alphabetically. If the Business starts with a letter it's no problem. For any business that starts with a number (i.e. 7 Eleven, 3 Margaritas, etc.) I'd like to file it in a folder entitled "0" which is preceding the "A"folder. I've applied the following formating to the token:  \0[0-9] this works in every case except when the number is followeed by a alpha character, in which case the result is the original number and not a 0. My regular expression ^.{1} is already specifing to only use the 1st character so I'm not sure why this is happening. See my examples below and also my screen shot of the result that does not work. Thank You for any help you can provide!

 

 

Test value: 4

Result:0    (good)

 

Test Value: 4t

result: 4    (bad)


Test Value: A

Result: A   (good)


Test Value: A1

Result: A   (good)


Test Value: 12345

Result: 0   (good)

 

Test Value: ABCD

Result: A    (good)

 

Bonus Question: To complicate it even further, what do you do with a business name that starts with a "#", which of course I'd like to file in the "0" folder as well.

RegularExpressionExampleQuestion.JPG
0 0

Replies

replied on March 4, 2014 Show version history

That is rather annoying, but why not just format the token ahead of time? Then you can use the token in the Query Data that you really want. Like, store the token to a new token with the Function "Trim" to remove any leading empty text. Then use a decision condition to say if the token starts with: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, # then to use the '0' and if not, use the first letter.

 

Testing out exactly what you have there in the image provided, I noticed even the examples of good values coming through for the numbers at the beginning get screwed up when a character comes after them (I tried '12345 d' and it now returns '1').

 

I think my first suggestion is the best since it will test out the first letter and then you will store a token with the value of the folder path you want to take. It's the best way to ensure reliability after having noticed that issue. 

 

^the above is a lie, you can just do it in two steps of formating the token, where the first step you change it to the first character and the second time you change it to be with the formatting '\0[0-9]'

1 0
replied on March 4, 2014

Formatting doesn't take regular expression syntax the way you have it.

 

I don't think you can do this with in-line pattern matching on the token. I think you will have to create a separate token for it.

 

You could get the first letter of the name, then run the token through a conditional sequences and if it's empty, you can set it to 0.

 

If you want to get the value with a single regex, you will still have to create a separate token, set it to look at "0%(QueryData_BusName)" and run a regex that specifies it wants the 0 if it's followed by a number or the first letter if 0 is followed by a letter. Something like ^(0)\d|^0([A-Z])

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

Sign in to reply to this post.