Skip to main content
Question

Compare two strings and output the matching parts and count of parts that matched.

  • October 14, 2020
  • 3 replies
  • 330 views

Trying to compare two columns that have strings concatenated by ' | ' and look like this:

 

COL A

abc | def | ghi

 

COL B

abc | xyz

 

Desired result:

COL C that contains the matching part of both strings.

 

In this case result should be: abc

 

COL D containing the count of matched parts of the string.

 

In this case, result should be: 1

 

Would appreciate your response.

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

virtualcitymatt
Celebrity
Forum|alt.badge.img+47

I think if you use a StingSearcher on COL A with COL B ​as the reg-ex to match and set to match all and create a list. This should give you the number of matches (COL D) as well as a list full of matches. Next use a ListConcatonator to squash the list into a single attribute (COL C) you can specify the delimiter for the attribute e.g., |

Let us know how you get on​


  • Author
  • October 14, 2020

Thanks for your reply. So, I tried the StringSearcher but it only outputs the first match. How do I change it to match all? And I'm still not sure how to get number of matches from this transformer.


virtualcitymatt
Celebrity
Forum|alt.badge.img+47

Thanks for your reply. So, I tried the StringSearcher but it only outputs the first match. How do I change it to match all? And I'm still not sure how to get number of matches from this transformer.

You will have to specify a list name. It will still output the first matched as attribute but there should also be a list attribute generated with matches. If the number of matches is not given you can use a listElementCounter to get the number​