Remove Rows which contains special characters Using RegEx

Dears,

How to Remove Rows which contains special characters : Digits & Some Specific letters →
Example :
1- Remove words containing french letters : é, è, à, …etc( aim is to keep only english words).
2- Remove words containing digits like phone numbers : 234-54-76-21.

I have the following RegEx Expression which can remove only words with digits:
Dt.AsEnumerable().Where(Function(x) not
System.Text.RegularExpressions.Regex.IsMatch(x(“Column_Name”).ToString.Trim,"[1]")).CopyToDataTable`

Can we have one expression for both cases ? Thanks in advance


  1. 0-9. ↩︎

Hi,

Can you share examples to be kept, too?

Regards,

1 Like

Hi @Yoichi ,

I’m following the topic: Remove the Rows contains Only Integer value
Here is only integer values but my case need to remove also rows containg words with some letters : é, è, à.

Note : Check example attached here for more clarification , what we have in input and what in output
Example.xlsx (9.1 KB)

I tried to modify the expression, unfortunately without success.

Hi,

For now, can you try the following expression?

Dt.AsEnumerable().Where(Function(x) not System.Text.RegularExpressions.Regex.IsMatch(x("Numeric").ToString.Trim,"[^A-Za-z]")).CopyToDataTable

Edit : I modified the expression due to wrong pattern

Regards,

1 Like

Thanks @Yoichi , But I got nothing as output in this case :roll_eyes:

Hi,

Sorry, I post wrong pattern. Can you try the following?

Dt.AsEnumerable().Where(Function(x) not System.Text.RegularExpressions.Regex.IsMatch(x("Numeric").ToString.Trim,"[^A-Za-z]")).CopyToDataTable

Regards,

1 Like

Excellent !!! :+1: , What if I want to remove one Some letter from A-Za-z range? let’s say letters : m or M ?

It’s Working like this : Dt.AsEnumerable().Where(Function(x) not System.Text.RegularExpressions.Regex.IsMatch(x(“Numeric”).ToString.Trim,"[^A-LN-Za-ln-z]")).CopyToDataTable

Thanks :+1:

1 Like

Hi Again,
I’m lost , need to keep composed words with hyphens “-” , Like : Sign-up :disappointed_relieved:

Hi,

Can you try express - at the beginning of the pattern, or escape it using \, as the following?

"[^-A-Za-z]"

OR

"[^A-Za-z\-]"

Regards,

1 Like

Both Works :+1: Thanks a lot @Yoichi

1 Like

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