Jump to content

Recommended Posts

  • Seeq Team

Seeq is often used to contextualize data with respect to production runs. These product runs may be a text or string signal that is the product code, or a very large numerical signal. Users commonly use Value Search to find a specific product run to further analyze. If they want to work with a couple of similar product runs, for example ones that start with or end with the same few letters or numbers, a few Value Searches followed by Composite Condition may be acceptable.

This approach may not be realistic if there are hundreds of different product codes to analyze. Recently a user asked for a trim function because they wanted to categorize all product codes by the first few letters the product code. For example, ABC-123-XYZ and ABC-456-DEF would both fall under the "ABC" product category. In Excel, users might use something like the functions LEFT and RIGHT to return the first few characters (LEFT(3) in this ABC example). One way to do this text or string manipulation in Seeq is to use the replace() function with a regular expression. 

Regular expressions can be intimidating to those who have not used them before, but they can also be very powerful. A little exploration on sites like https://regex101.com can help evaluate what kind of regular expression is appropriate for a specific use case.

Given the above example product codes, the below Seeq Formula incorporates a regular expression within the replace() function to parse the string signal by the "-" and then return only the first part of that parsed string based on the "$1".

$productcode.replace('/(.*)-(.*)-(.*)/', '$1')

image.png

I could similarly categorize by the last three characters with a function like

$productcode.replace('/(.*)-(.*)-(.*)/', '$3')

Once this simplified text signal is available, any other tools can be used in the analysis. If the product code was a very large number instead of a string, apply toString() to benefit from the replace() function. 

There are often many ways to solve a problem. An alternate approach to categorize product codes like this might be to pair toCapsules() and filter() off the Value property in Formula. Perhaps the best solution is incorporating regular expressions into Value Search like in the example below to create conditions any time the product code starts with ABC (/^ABC.*/) or any time it ends with XYZ (/.*XYZ$/). The slashes here indicate regular expressions should be used, similar to searching with regex in the Data Pane. 

image.png

But this approach is likely not obvious or easy without a little experience with regular expressions. So while regular expressions may feel foreign at first, do not be intimidated! They really can pay off in the long run.

  • Like 3
Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...