Using Regex expression in LinqQuery

Hi All,

I am trying to use regex in linq query but getting errors

ExtractDataTable.AsEnumerable.Where(Function(x) (System.Text.RegularExpressions.Regex.Match(x(“List price (Quantity)”).ToString,“\d+.\d{2}\d*(?<=[1-9])|\d+.\d{2}”).Value).CopyToDataTable

My steps are first I should regex in column(“List price (Quantity)”) in Linq Query and then use the final query in the next step of If Condition

ExtractDataTable.AsEnumerable().

Where(Function(row) row.Field(Of String)(“Charges”)=sku_name AndAlso

row.Field(Of String)(“List price (Quantity)”) <> sku_listprice).Count > 0

@Anil_G any thoughts on this ?

We would suggest to do some more preparations. In general give a try at

(From d in ExtractDataTable.AsEnumerable
Let rv = System.Text.RegularExpressions(d("ColNameOrIndex").toString.Trim, "YourRegexPattern").Value
Where Here_A_Boolean_Return_From_Check_is_required
Select r=d).CopyToDataTable

Above Statement has at least the issues:

  • → (Syst - Bracket
  • no Boolean returned from Where Check Lambda

[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum
And also:

we had seen Regex.Match and mentioned the not available lambda Boolean return.

Maybe the intention was about using Regex.isMatch
[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

But then .Value is not needed

@ppr

Shall I not write .Value ?

What should be the correct expression for the below query?

ExtractDataTable.AsEnumerable.Where(Function(x) (System.Text.RegularExpressions.Regex.Match(x(“List price (Quantity)”).ToString,“\d+.\d{2}\d*(?<=[1-9])|\d+.\d{2}”).Value).CopyToDataTable

@dutta.marina

Ideally this si what you can use

ExtractDataTable.AsEnumerable.Where(Function(x) System.Text.RegularExpressions.Regex.IsMatch(x("List price (Quantity)").ToString,"\d+.\d{2}\d*(?<=[1-9])|\d+.\d{2}")).CopyToDataTable

Cheerd

1 Like

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