Using regex to find similar values in datatable

Hi there, I’m looking to pull a string from a datatable and then search that same data table for a similar string with a different year in the name.

For example - IF “product name 2020” contains “2020”, then find “product name 2019”

I’m using a read range to populate the datatable, then I’m using a For Each Row to find which rows contain “2020”, at this point I’m storing the other data I’m interested in.

Within this first For Each Row I’m using a nested For Each Row, to search the datatable for names similar to the current row name. I then want to use an IF condition determine whether these values match, using regex to allow for the difference in year.

I’m struggling with the regex necessary to create the correct IF condition. Any help greatly appreciated :slight_smile:

i hope we can simply check with a contains activity
like this in if condition
if this condition passes it will goto THEN part where we can include any activity we want

hope this would help you
Kindly correct me if i have understood the query wrongly
Cheers @jakegill

Hi Pal, many thanks for your response :slight_smile:

I’m using the contains method as you have suggested in the first IF loop. This gets me a row(name) that contains “2020” - let’s call it ‘Product Name 2020’.

I’m then using a nested For Each to search through the data table again to find a similar product with a name that almost matches except with a different year - e.g. Product Name 2019 - let’s call this ‘Product Name YYYY’.

I want to check whether the second search pulls a value that matches the first search. I’m not sure how to use regex to match these names considering they have different years.


for this again we can use a same if condition like inside the inner if condition
row(“yourcolumnname”).ToString.Contains(“Product Name”)

Hope that would work either
kindly correct me if i m wrong
Cheers @jakegill

Sure, but I think there would have to be a stage in between that separates the product name from the YYYY so I’d be able to use the product name to search. This was why I originally thought of regex to find a partial match where most of the product name matches but the year at the end can vary.

Thanks for your help so far :slight_smile:

Can you post few examples so I can try to create Regex for your case?

Thanks! I’ve now found it’s better to clean the data in excel and avoid regex all together. Appreciate your offer though.

Hi Pal, thanks for your help with this. I’m using the string.contains method for both For Each Rows as you’ve suggested. I’ve cleaned the data in excel so I can avoid regex. It’s now working as hoped.



1 Like

Cheers @jakegill

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.