# How Extract String

**URL:** <https://forum.uipath.com/t/how-extract-string/387807>\
**Category:** Studio\
**Tags:** question, studio, system, activities\
**Created:** [January 2, 2022, 10:04am UTC](https://forum.uipath.com/t/how-extract-string/387807 "2022-01-02T10:04:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Teaf](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/teaf/32/176959_2.png) [@Teaf](https://forum.uipath.com/u/Teaf)\
**Post date:** [January 2, 2022, 10:04am UTC](https://forum.uipath.com/t/how-extract-string/387807/1 "2022-01-02T10:04:37Z")

</div>

Hi ,  
I have the below string:

- Home 022-024272-701
- TAIEF Ibraheem 465234N01T8A
- Home 742419F55CT1

I need to peek what before Number For example :

- Home
- TAIEF Ibraheem
- Home

Could anyone share a regex or any other way of getting this Please .

Thanks .

---

<div class="post-metadata">

**Author:** ![supermanPunch](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/supermanpunch/32/133652_2.png) [@supermanPunch](https://forum.uipath.com/u/supermanPunch)\
**Post date:** [January 2, 2022, 10:30am UTC](https://forum.uipath.com/t/how-extract-string/387807/2 "2022-01-02T10:30:46Z")

</div>

Hi @Teaf ,

Based on the Inputs you have provided, there seems to be a Space before a Number and the data before the Space constitutes to your Required Data to be extracted.

Keeping this mind, I think you can test with the below Expression :

```auto
(.*)\s\d

```

`(.*)` is your required data, which in the Expression is a Group. Hence, You would need to get the First Group from the Result Match in the below way.

`System.Text.RegularExpressions.Regex.Match(InputStr,"(.*)\s\d").Groups(1).ToString.Trim`

`InputStr` is the Input data variable

Let us know if this Expression doesn’t work for all your Test Data.

---

<div class="post-metadata">

**Author:** ![Teaf](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/teaf/32/176959_2.png) [@Teaf](https://forum.uipath.com/u/Teaf)\
**Post date:** [January 2, 2022, 11:18am UTC](https://forum.uipath.com/t/how-extract-string/387807/3 "2022-01-02T11:18:02Z")

</div>

Thanks for your response.

Unfortunately doesn’t work for all data such as TAIEF Ibraheem 465234N01T8A

---

<div class="post-metadata">

**Author:** ![supermanPunch](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/supermanpunch/32/133652_2.png) [@supermanPunch](https://forum.uipath.com/u/supermanPunch)\
**Post date:** [January 2, 2022, 11:32am UTC](https://forum.uipath.com/t/how-extract-string/387807/4 "2022-01-02T11:32:55Z")

</div>

That is Strange, It does seem to be working on my end. Please let us know what is the exact input data that you have provided.

@Teaf You can Check the below Image of Extracted data.

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

---

<div class="post-metadata">

**Author:** ![Teaf](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/teaf/32/176959_2.png) [@Teaf](https://forum.uipath.com/u/Teaf)\
**Post date:** [January 2, 2022, 11:40am UTC](https://forum.uipath.com/t/how-extract-string/387807/5 "2022-01-02T11:40:56Z")

</div>

Exact input :

TAIEF AL BAHUSSAIN 465234N01T8A AL RAJHI BANKING AND INV T CORP BR 192 JEDDAH EX Rate : SAR 1.0000000 AL RAJHI BANKING AND INV T CORP

**Another Example :**

CHARGES SAR 10.00 267128V1267A BANK AL BILAD TOTAL VAT SAR1,05 ON CHARGE AMOUNT SAR10,

I need to peek :

- TAIEF AL BAHUSSAIN
- CHARGES

---

<div class="post-metadata">

**Author:** ![arivu96](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@arivu96](https://forum.uipath.com/u/arivu96)\
**Post date:** [January 2, 2022, 12:57pm UTC](https://forum.uipath.com/t/how-extract-string/387807/6 "2022-01-02T12:57:55Z")

</div>

Hi @Teaf ,  
Use Below pattern and take only first occurrence  
`.*?([0-9])`

Regards,  
Arivu

---

<div class="post-metadata">

**Author:** ![Sudharsan\_Ka](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sudharsan_ka/32/459826_2.png) [@Sudharsan\_Ka](https://forum.uipath.com/u/Sudharsan_Ka)\
**Post date:** [January 3, 2022, 5:14am UTC](https://forum.uipath.com/t/how-extract-string/387807/8 "2022-01-03T05:14:44Z")

</div>

HI @Teaf

Try with the below Expression  
\S.+(?=\s\d)

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

Regards  
Sudharsan

---

<div class="post-metadata">

**Author:** ![Teaf](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/teaf/32/176959_2.png) [@Teaf](https://forum.uipath.com/u/Teaf)\
**Post date:** [January 3, 2022, 6:21am UTC](https://forum.uipath.com/t/how-extract-string/387807/9 "2022-01-03T06:21:04Z")

</div>

doesn’t work. The output :

- TAIEF AL BAHUSSAIN 4
- CHARGES SAR 10

---

<div class="post-metadata">

**Author:** ![arivu96](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@arivu96](https://forum.uipath.com/u/arivu96)\
**Post date:** [January 3, 2022, 6:38am UTC](https://forum.uipath.com/t/how-extract-string/387807/10 "2022-01-03T06:38:44Z")

</div>

Hi @Teaf ,  
Try below Regex pattern  
`^\S.+?(?=\s\d)`

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

Regards,  
Arivu

---

<div class="post-metadata">

**Author:** ![Robinnavinraj\_S](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/robinnavinraj_s/32/177041_2.png) [@Robinnavinraj\_S](https://forum.uipath.com/u/Robinnavinraj_S)\
**Post date:** [January 3, 2022, 7:08am UTC](https://forum.uipath.com/t/how-extract-string/387807/11 "2022-01-03T07:08:22Z")

</div>

Hi @Teaf

Can you try out this expression

```auto
((?<=\w\s)(\d+|\d)[\-\w]+)

```

Thanks  
Robin

---

<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:** [January 6, 2022, 7:09am UTC](https://forum.uipath.com/t/how-extract-string/387807/12 "2022-01-06T07:09:18Z")

</div>

Closed on January 6, 2022, 7:09am UTC

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