Regular Expression remove words

Hi Team,

I have an input
SourceName = AND THE ABC LIMITED
In asset i have values like AND, THE
In loop i am accessing these asset values and checking in input that any words contains AND or THE present in the SourceName.
If they are present it should remove AND & THE. If any one is there it will remove accordingly. I am using the below code which removed only AND not THE
System.Text.RegularExpressions.Regex.Replace(InputName,“^(”+string.Join(“|”,item.ToString.Split(“,“c))+”,”")
Kindly provide your inputs in this regard.

why have you used c? What is format of item?

Have a look here on how to run multiple regexes over an item

A classical but well working approach would look like this:
grafik

On which asset value can be integrated to the for each values by
grafik

1 Like

In Asset values are - THE,AND
Thats y used - item.ToString.Split(",“c))
Let me know if i need to do a code change.

The asset value will be added further or can be removed also THE,AND,WAS…(will be updated by the user so its dynamic). Input and asset values are in below order.
Input - AND THE ABC THE AND LIMITED
Asset contains - THE,AND
Expected output - ABC THE AND LIMITED
Actual outout is - THE ABC THE AND LIMITED
Also we need to ensure that if relevant values in asset falls in between ABC LIMITED should not be removed.

@Balan try this

System.Text.RegularExpressions.Regex.Replace(InputName,"("+String.Join("|", item.ToString.Split(","c))+")”, "")

example

System.Text.RegularExpressions.Regex.Replace("WHAT IS YOUR NAME AND ADDRESS","("+String.Join("|", "AND,IS".ToString.Split(","c))+")”, "")

output - “WHAT YOUR NAME ADDRESS”