How to filter the data from Data table using filter condition like starts X*BA* or X*DA*

Hi,

I have data table with multiple columns and filter the data based on “Value added” column with starts text with XBA or XDA(in place of * it can be anything like 0-9 or A to Z) and different date column data need to be pick. Could you please help me on this.
Please find the below sample data

Input:

Category Brand Model Modification date Value added
abc1 exe0001 rgg345 9/6/2024 X1BA2Testing1
abc2 exe0002 rgg346 9/7/2024 XABACTesting2
abc3 exe0003 rgg347 9/8/2024 X0BAETesting3
abc4 exe0004 rgg348 9/9/2024 X5DAATesting3
abc5 exe0005 rgg349 9/10/2024 X7DAZTesting3
abc6 exe0006 rgg350 9/6/2024 X7DAZTesting4
abc7 exe0007 rgg351 9/6/2024 XODAKTesting5
abc8 exe0008 rgg352 9/6/2024 X0BAETesting3
abc9 exe0009 rgg353 9/6/2024 X7DAZTesting4

Output: Data to be filter with distinct dates(if distinct dates not found we can pick any 3 rows but 3 rows need to select as output)

Output data with starts with XBA

Category Brand Model Modification date Value added
abc1 exe0001 rgg345 9/6/2024 X1BA2Testing1
abc2 exe0002 rgg346 9/7/2024 XABACTesting2
abc3 exe0003 rgg347 9/8/2024 X0BAETesting3

Output data with starts with XDA

Category Brand Model Modification date Value added
abc4 exe0004 rgg348 9/9/2024 X5DAATesting3
abc5 exe0005 rgg349 9/10/2024 X7DAZTesting3
abc6 exe0006 rgg350 9/6/2024 X7DAZTesting4

TIA

@Manaswini_UI

use linq using assign as below

dt = dt.AsEnumerable.Where(function(x) System.Text.RegularExpressions.Regex.Match(x("Value added").ToString.Trim,"^X.*BA")).CopyToDataTable

cheers

Hi @Manaswini_UI
Try below linq query
outputDataTable = (From row In dt.AsEnumerable()
Where System.Text.RegularExpressions.Regex.IsMatch(row.Field(Of String)(“Value added”), “^(XBA|XDA)”
Group row By modificationDate = row.Field(Of DateTime)(“Modification date”).ToString(“MM/dd/yyyy”) Into Group
Select Group.First()).Take(3).CopyToDataTable()

Staring starts with X[0-9/A-Z]BA[0-9/A-Z] similarly for X[0-9/A-Z]DA[0-9/A-Z]

[0-9/A-Z]–here it may come number from 0-9 or letter AtoZ

Hi, could you please help on this

this it not working

As mentioned string starts with X[0-9/A-Z]BA[0-9/A-Z] in place of [0-9/A-Z] it can be anything letter or number

@Manaswini_UI

Try this

^X.{1}BA.*

Cheers

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