Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

String Pattern Matching

Hello my QV friends.  I am trying to figure out the best way to find string patterns.  For example, the string in question, if it has values for all sections, can look like this:

1234*12345678*1234567891*12345678*1234

So that would be 4 characters, asterisk, then 8, asterisk, 10, asterisk, 8, asterisk and then 4.

However, some times there may not be a value in the first section of 8, like this:

1234**1234567891*12345678*1234

Or maybe sometimes it can be like this:

1234*12345678**12345678*1234

Should I be using WILDMATCH for this?  I am trying to capture all possible variations.  Any other ideas?  Thank you.

*****UPDATE******

I have been working on this now for a little while and have the following:

TEST:

LOAD SAP_GL_CODE,

  IF(LEN(SAP_GL_CODE) = 38 AND ,'YES','NO') AS TEST,

  IF(SAP_GL_CODE LIKE '????' & chr(42) & '????????' &chr(42)& '??????????' &chr(42)& '????????' &chr(42)& '????','YES','NO') AS ALL

RESIDENT DATA;

The code works.

My problem now is that if I put something like

IF(SAP_GL_CODE LIKE '????' & chr(42) & chr(42) & '??????????' &chr(42)& '????????' &chr(42)& '????','YES','NO') AS NOT_ALL

this code doesn't work.  Does anyone know how to write two chr()'s back to back??  Thanks.

2 Replies
whiteline
Master II
Master II

Hi.

Perhaps you had better to try regular expressions to capture all possible variations.

There are some examples how to use them in a macro.

Anonymous
Not applicable
Author

Thank you for replying whiteline.  Actually figured it out with help from a colleague.  Here's what my code ended up looking like:

IF(LEN(SAP_GL_CODE) = 30, MID(SAP_GL_CODE,6,8),

  IF(LEN(SUBFIELD(SAP_GL_CODE,'*',2))<2 OR SUBFIELD(SAP_GL_CODE,'*',2)='' OR ISNULL(Subfield(SAP_GL_CODE,'*',2)),

  MID(SAP_GL_CODE,7,10),'')) AS PROFIT_CENTER,