Filter a datatable using a String Value which have wildcards

Hi all,

I am trying to filter a datatable column on basis of a String which contains the Wildcards.
I am not able to achieve it using Filter datatable activity and now I am trying the Regex Method, It is also not giving all the results.
Table Column - Model contains ABC-VK, ABC, ABC VK
String Value is - ABCVK*, ABC, *ABCVK
Let me know if in case it is possible and how to achieve it.

Thanks in advance…

@Yoichi @Gokul001 @Anil_G @Palaniyappan

Hi,

Can you try as the following?

 arrDr = dt.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,pattern.Replace("*",".*"))).ToArray

Regards,

@Vishal.Khurana

try this linq query

DataTable filteredTable = yourDataTable.AsEnumerable()
    .Where(row => Regex.IsMatch(row["Model"].ToString(), "^" + yourFilterString.Replace("*", ".*") + "$"))
    .CopyToDataTable();

cheers…!

It is not working on the cases where there is * in between the string like “*** ABC*VK**”.
But giving output on the cases of ABC.

Thanks,
Vishal

Unfortunately, It is not working.

Giving this error while initiating in Assign.
BC30157: Leading ‘.’ or ‘!’ can only appear inside a ‘With’ statement.

HI,

In general ,wildcard (*) means 0 or more characters. Is it same as your expectation?
Also can you write expression using </> menu because asterisk is special character in this forum and it’s not shown correctly.

Regards,

Hi @Yoichi , Thanks for your time.

The Expectation behind using Wildcard is that I have Values like this (ABC-VK. (ABCVK, ABC VK-VI) in dt

To Filter from this Column, I am adding wildcard so that each value will come in my Filter ABC, ABC-VK, ABCVKVI …
I am adding </> in Start, end and Mid of String, Also replacing any Special character and space with </>
Getting Value of String like this </>ABC</>and </>ABC</>VK</>VI</>

After this Step using the Solution that you Provided, it is not working for cases which have<*/> in mid of String.

How can I filter in this Scenario.
Hope you get the Problem Statement. Thanks

Hi,

If my understanding is correct, my first sample will work.

If input datatable is as the following, the expression will return the first row.

Can you check the following sample, too?
Sample20231122-7L.zip (3.0 KB)

PS.
To write special character, can you try to use the following </> menu
image

Regards,