Skip to main content

Hi,

 

I am currently trying to create a new attribute based upon a number of sub-string matches. Currently this is using the attribute creator and a condition statement (lots of else if's). This is currently works, however, I need to extend this to provide all the matches rather than just the first match. Some of the original values may meet one or more of the conditions for the new classification. I know I could do this in a series of subsequent attribute creators, but there would need to be over a hundred individual ones. Does anyone have any advice on how I could do this more streamlined!

 

Thanks!

You could probably achieve this with StringPairReplacer + StringSearcher

StringPairReplacer checks a string for all search strings, and performs an action for every match found (The action being a replacement of the substring found).

 

The String Pairs input into StringPairReplacer could be something like:

Yellow Match001 Blue Match002 Green Match003

 

If the string being searched was something like "Yellow is the new Green", then StringPairReplacer will return this as: "Match001 is the new Match003"

 

If this output was then input into StringSearcher now the string format "Matchxxx" is a known string RegEx pattern of Match\\d{3}. If the option is enabled in StringSearcher to return All Subexpression matches in a List, then this will return for the example string above the following List:

SubExprMatchList{0} = Match001

SubExprMatchList{1} = Match003

 

So this tells you exactly which substrings matched by a numerical indicator as to which ones in the String Pair List matched.

 

The only word of caution is that this won't work without modification if any of the search strings are substrings of each other. Eg. Needing to find matches of "Our" and "Ourselves" separately.

 

For this you can use a similar technique but instead inside StringSearcher by using a RegEx search pattern of (Yellow|Blue|Green) (With "|" being the equivalent of OR in RegEX)

 

This will take the sample string and return a List of all Subexpression matches as

SubExprMatchList{0} = Yellow

SubExprMatchList{1} = Green


Reply