Regex with linq query

Hi,I’m Using linq query for finding values and copy to another table.but it’s not working ,Please correct me.

dt_ListOfExcelfiles.AsEnumerable().Where(Function(x) System.Text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension(x(“ExcelFilePath”).ToString.Replace(“”,system.Environment.UserName)),“(RegSuppq|Regsuppq)\d+\s+-\s+(Draft|draft)\s+\d+”).ToString).copytodatatable()

HI @yashashwini2322

What error do you receive?

Regards
Sudharsan

@yashashwini2322,

What you are trying to do? may be there could be another, easier way.

Thanks,
Ashok :slight_smile:

Hi @yashashwini2322

Try this:

filteredDt = (From row In dt_ListOfExcelfiles.AsEnumerable()
                  Let filePath = row.Field(Of String)("ExcelFilePath")
                  Where System.Text.RegularExpressions.Regex.IsMatch(Path.GetFileNameWithoutExtension(filePath.Replace("",system.Environment.UserName)), "(RegSuppq|Regsuppq)\d+\s+-\s+(Draft|draft)\s+\d+")
                  Select row).CopyToDataTable()

Hope it helps!!

Hi @yashashwini2322

Your query is quite confusing, do more elaborate your query. If possible provide us the input and expected output data.

Hello @yashashwini2322
Try This

dt_ListOfExcelfiles.AsEnumerable().Where(Function(x) System.Text.RegularExpressions.Regex.
 IsMatch(Path.GetFileNameWithoutExtension(x("ExcelFilePath").ToString().Replace("", Environment.UserName)),"(RegSuppq|Regsuppq)\d+\s+-\s+(Draft|draft)\s+\d+")).
 CopyToDataTable()