# Regular Expression remove words

**URL:** <https://forum.uipath.com/t/regular-expression-remove-words/320787>\
**Category:** Activities\
**Tags:** question, ocr, activities\
**Created:** [June 7, 2021, 7:46am UTC](https://forum.uipath.com/t/regular-expression-remove-words/320787 "2021-06-07T07:46:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Balan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/balan/32/176658_2.png) [@Balan](https://forum.uipath.com/u/Balan)\
**Post date:** [June 7, 2021, 7:46am UTC](https://forum.uipath.com/t/regular-expression-remove-words/320787/1 "2021-06-07T07:46:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kumar.varun2](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/kumar.varun2/32/215924_2.png) [@kumar.varun2](https://forum.uipath.com/u/kumar.varun2)\
**Post date:** [June 7, 2021, 8:21am UTC](https://forum.uipath.com/t/regular-expression-remove-words/320787/2 "2021-06-07T08:21:39Z")

</div>

> [@Balan](#):
>
> item.ToString.Split(",“c))

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

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [June 7, 2021, 8:25am UTC](https://forum.uipath.com/t/regular-expression-remove-words/320787/3 "2021-06-07T08:25:44Z")

</div>

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

> [@Regex Matches Overlapping Patterns](https://forum.uipath.com/t/regex-matches-overlapping-patterns/240589/2):
>
> @brasheva Welcome to the Forum find a demo xaml running multiple patterns and returning a list\<Match\> here: [RegEx\_RunMultiplePatterns.xaml](https://forum.uipath.com/uploads/short-url/e45HdluoAX8ALYoEabCCx4YuLnl.xaml) (6.8 KB)

A classical but well working approach would look like this:  
 ![grafik](https://global.discourse-cdn.com/uipath/original/3X/0/6/0698c2ea663fff39fe98cd87361e8aa44c116f5a.png)

On which asset value can be integrated to the for each values by  
 ![grafik](https://global.discourse-cdn.com/uipath/original/3X/7/2/721021f9985f86fd6c35149b101a3cb0b758bd7b.png)

---

<div class="post-metadata">

**Author:** ![Balan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/balan/32/176658_2.png) [@Balan](https://forum.uipath.com/u/Balan)\
**Post date:** [June 7, 2021, 8:40am UTC](https://forum.uipath.com/t/regular-expression-remove-words/320787/4 "2021-06-07T08:40:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kumar.varun2](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/kumar.varun2/32/215924_2.png) [@kumar.varun2](https://forum.uipath.com/u/kumar.varun2)\
**Post date:** [June 7, 2021, 10:20am UTC](https://forum.uipath.com/t/regular-expression-remove-words/320787/5 "2021-06-07T10:20:56Z")

</div>

@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”
