Using Regex to Replace Text in a Datatable

Greetings,

I am very close on this one, but for some reason the code I have within my assign is saying “end of expression expected”

Using the Assign activity: (SKU2 is the left side of the assign)

SKU2 = (From d In SKU.AsEnumerable 
Let c = System.Text.RegularExpressions.Regex.Replace(d("SKU Column"),"\d+\s+\d{1,3},\d{3}.\d{2}\s+\s+\d{1,3},\d{3}.\d{2}\s+\d{1,3}.\d{2}",""))
Let cs = New Object(){c} 
Select SKU2.Rows.Add(cs)).CopyToDataTable

Can anyone help me figure out why I am getting this error?

(Yes, SKU2 and SKU are both 1 column datatables)

On a simpler, similar automation, which consists of 2 assign activities and one message box, which is working, I have the following:

Assign:

str = "[ASE-FP-WAN 1 23,931.00  23,931.00 665.00 -10G]"

Assign:

finalResult = System.Text.RegularExpressions.Regex.Replace(str,"\d+\s+\d{1,3},\d{3}.\d{2}\s+\s+\d{1,3},\d{3}.\d{2}\s+\d{1,3}.\d{2}","")

“finalResult” in a message box displays “[ASE-FP-WAN -10G]” - Which is what I am trying to achieve in the datatable.

Hopefully @ppr can come to the rescue on this one! Thank you!

can you try

(From d In SKU.AsEnumerable 
Let c = System.Text.RegularExpressions.Regex.Replace(d("SKU Column").toString,"\d+\s+\d{1,3},\d{3}.\d{2}\s+\s+\d{1,3},\d{3}.\d{2}\s+\d{1,3}.\d{2}","")
Let cs = New Object(){c} 
Select r = SKU2.Rows.Add(cs)).CopyToDataTable

Thank you for the very quick response.

I used your code, but it is still giving me “end of expression expected” error.

@Sc100
see updated code above

1 Like

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