# How to get data between two String

**URL:** <https://forum.uipath.com/t/how-to-get-data-between-two-string/404998>\
**Category:** Forum\
**Tags:** split, question, forum, regex, system, activities\
**Created:** [March 7, 2022, 1:12pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998 "2022-03-07T13:12:05Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![TUSHAR\_DIWASE](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@TUSHAR\_DIWASE](https://forum.uipath.com/u/TUSHAR_DIWASE)\
**Post date:** [March 7, 2022, 1:12pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/1 "2022-03-07T13:12:05Z")

</div>

Hi,

How do i get string between two string(“for”).  
For ex.:- “Outstanding Bill for xyz company for Mar 20”  
expected output: xyz

But sometime company name contain  
So basically i want complete string between first “for” and last “for”.

Please Suggest

---

<div class="post-metadata">

**Author:** ![Gokul001](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gokul001/32/462734_2.png) [@Gokul001](https://forum.uipath.com/u/Gokul001)\
**Post date:** [March 7, 2022, 1:15pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/2 "2022-03-07T13:15:24Z")

</div>

Hi @TUSHAR_DIWASE

Use Assign activity  
LHS - Create an variable  
RHS - **System.Text.RegularExpressions.Regex.match(InputString, “(?\<=Outstanding\sBill\sfor\s)(\S+)”).Tostring**

> **[regex101: build, test, and debug regex](https://regex101.com/r/ZnafYR/1)**
>
> Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.

Regards  
Gokul

---

<div class="post-metadata">

**Author:** ![ashwin.ashok](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashwin.ashok/32/300916_2.png) [@ashwin.ashok](https://forum.uipath.com/u/ashwin.ashok)\
**Post date:** [March 7, 2022, 1:22pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/3 "2022-03-07T13:22:00Z")

</div>

Hi @TUSHAR_DIWASE ,

Is the keyword company always present?  
If so, then this ought to work:

![image](https://global.discourse-cdn.com/uipath/original/4X/a/4/3/a4365520d46c4f87d509ca18ae4175be80ecd583.png)

> **[regex101: build, test, and debug regex](https://regex101.com/r/0WXViS/1)**
>
> Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.

```auto
System.Text.RegularExpressions.Regex.Match(str_variable,"[^\s]+(?=\scompany)").Value

```

**Kind Regards,  
Ashwin A.K**

---

<div class="post-metadata">

**Author:** ![TUSHAR\_DIWASE](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@TUSHAR\_DIWASE](https://forum.uipath.com/u/TUSHAR_DIWASE)\
**Post date:** [March 7, 2022, 1:25pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/4 "2022-03-07T13:25:25Z")

</div>

@ashwin.ashok thanks but “Outstanding Bill” and both “for” word are constant.  
so i want string between first and last “for”

---

<div class="post-metadata">

**Author:** ![Gokul001](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gokul001/32/462734_2.png) [@Gokul001](https://forum.uipath.com/u/Gokul001)\
**Post date:** [March 7, 2022, 1:29pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/5 "2022-03-07T13:29:40Z")

</div>

HI @TUSHAR_DIWASE

> [@TUSHAR\_DIWASE](#):
>
> How do i get string between two string(“for”).

Try this expression

Use Assign activity  
LHS - Create an variable  
RHS - **System.Text.RegularExpressions.Regex.match(InputString,“(?s)for(.\*?) for”).Groups(1)**

 ![image](https://global.discourse-cdn.com/uipath/original/4X/c/5/4/c5488908bf51d6297ed071138ea83aef6266ec3d.png)

Regards  
Gokul

---

<div class="post-metadata">

**Author:** ![TUSHAR\_DIWASE](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@TUSHAR\_DIWASE](https://forum.uipath.com/u/TUSHAR_DIWASE)\
**Post date:** [March 7, 2022, 1:34pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/6 "2022-03-07T13:34:59Z")

</div>

@Gokul001 an you please assist me about the LHS type of variable

---

<div class="post-metadata">

**Author:** ![ashwin.ashok](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashwin.ashok/32/300916_2.png) [@ashwin.ashok](https://forum.uipath.com/u/ashwin.ashok)\
**Post date:** [March 7, 2022, 1:35pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/7 "2022-03-07T13:35:26Z")

</div>

Hi @TUSHAR_DIWASE ,

Is this what you meant?

> **[regex101: build, test, and debug regex](https://regex101.com/r/JLXnBE/1)**
>
> Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.

![image](https://global.discourse-cdn.com/uipath/original/4X/4/7/e/47ee0cc42cc82cf71c0ec13bfd68d823f68a4fbb.png)

![image](https://global.discourse-cdn.com/uipath/original/4X/1/8/9/189ca092c86b9c4c568efeb5923cfb869b7627b0.png)

```auto
System.Text.RegularExpressions.Regex.Match(str_variable,"(?<=for\s)(.*)(?:\s.*)(?=\sfor)").Groups(1)

```

**Kind Regards  
Ashwin A.K**

---

<div class="post-metadata">

**Author:** ![Gokul001](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gokul001/32/462734_2.png) [@Gokul001](https://forum.uipath.com/u/Gokul001)\
**Post date:** [March 7, 2022, 1:35pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/8 "2022-03-07T13:35:37Z")

</div>

Hi @TUSHAR_DIWASE

> [@TUSHAR\_DIWASE](#):
>
> LHS type of variable

String Type variable

---

<div class="post-metadata">

**Author:** ![TUSHAR\_DIWASE](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@TUSHAR\_DIWASE](https://forum.uipath.com/u/TUSHAR_DIWASE)\
**Post date:** [March 7, 2022, 1:40pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/9 "2022-03-07T13:40:59Z")

</div>

![image](https://global.discourse-cdn.com/uipath/original/4X/3/5/7/35787462a075e40fee8a896f32849bbdad199971.png)  
getting below error

---

<div class="post-metadata">

**Author:** ![TUSHAR\_DIWASE](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@TUSHAR\_DIWASE](https://forum.uipath.com/u/TUSHAR_DIWASE)\
**Post date:** [March 7, 2022, 1:44pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/10 "2022-03-07T13:44:29Z")

</div>

@Gokul001 string is not accepting variable type

---

<div class="post-metadata">

**Author:** ![Gokul001](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gokul001/32/462734_2.png) [@Gokul001](https://forum.uipath.com/u/Gokul001)\
**Post date:** [March 7, 2022, 1:47pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/11 "2022-03-07T13:47:36Z")

</div>

HI @TUSHAR_DIWASE

Try this expression

```auto
System.Text.RegularExpressions.Regex.Match("for is for","(?s)for(.*?) for").Groups(1).ToString

```

 ![image](https://global.discourse-cdn.com/uipath/original/4X/9/9/f/99fdfae518bfb754b044a3e9154bcc8a31ba748a.png)

Regards  
Gokul

---

<div class="post-metadata">

**Author:** ![Gokul001](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gokul001/32/462734_2.png) [@Gokul001](https://forum.uipath.com/u/Gokul001)\
**Post date:** [March 7, 2022, 1:48pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/12 "2022-03-07T13:48:52Z")

</div>

> [@TUSHAR\_DIWASE](#):
>
> string is not accepting variable type

End of the expression after **Groups(1)** just give the **.Tostring**

Regards  
Gokul

---

<div class="post-metadata">

**Author:** ![Prasanth\_Thangavelu](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@Prasanth\_Thangavelu](https://forum.uipath.com/u/Prasanth_Thangavelu)\
**Post date:** [March 7, 2022, 2:00pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/13 "2022-03-07T14:00:45Z")

</div>

> [@TUSHAR\_DIWASE](#):
>
> Outstanding Bill for xyz company for Mar 20”

You can use the below regex for getting the data previous to fixed variable

\*\*

> [^\s]+(?=\scompany)

\*\*

Use this regex syntax to get the data between two labels/fixed variables

\*\*

> (?\<=for).\*(?=for)

\*\*

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [March 10, 2022, 2:01pm UTC](https://forum.uipath.com/t/how-to-get-data-between-two-string/404998/14 "2022-03-10T14:01:03Z")

</div>

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