# Find substring , extract it with its corresponding value from String source

**URL:** <https://community.postman.com/t/find-substring-extract-it-with-its-corresponding-value-from-string-source/43976>\
**Category:** Help Hub\
**Tags:** string, extract, find\
**Created:** [February 14, 2023, 3:50pm UTC](https://community.postman.com/t/find-substring-extract-it-with-its-corresponding-value-from-string-source/43976 "2023-02-14T15:50:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![perezb2022](https://avatars.discourse-cdn.com/v4/letter/p/e495f1/32.png) [@perezb2022](https://community.postman.com/u/perezb2022)\
**Post date:** [February 14, 2023, 3:50pm UTC](https://community.postman.com/t/find-substring-extract-it-with-its-corresponding-value-from-string-source/43976/1 "2023-02-14T15:50:53Z")

</div>

Good Day Everyone

I have an Issue, hope you can help me .

I have a string tag in the Response, that string looks like this  
"|Search=name|codProd=ABC\_73335610|CNAD\_ENTRY=1551|UFO=pa|UFD=sa|natOp=111|

What I need is to extract a substring for instance “UFO” from pipe to pipe , final result will be like UFO=pa , then save it into a variable  
Also not all string will have UFO so Need to be able to consider that.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [February 14, 2023, 4:17pm UTC](https://community.postman.com/t/find-substring-extract-it-with-its-corresponding-value-from-string-source/43976/2 "2023-02-14T16:17:13Z")

</div>

You can use split() to create an array

```auto
let string = "|Search=name|codProd=ABC_73335610|CNAD_ENTRY=1551|UFO=pa|UFD=sa|natOp=111";
var array = string.split('|');
console.log(array);

```

![image](https://us1.discourse-cdn.com/getpostman/original/3X/8/b/8b9573db292f9d7ccba586b31d13bab2a269e214.png)

You can target the element directly by its array index.

```auto
console.log(array[4]);

```

Or you can use the JavaScript find function.

```auto
let search = array.find(element => element.includes("UFO"));
console.log(search); 

```

Both ways will return the “UFO=PA” string.

![image](https://us1.discourse-cdn.com/getpostman/original/3X/1/1/11c0520d1a34ca56eddbdc6860d275b61854a7af.png)

---

<div class="post-metadata">

**Author:** ![perezb2022](https://avatars.discourse-cdn.com/v4/letter/p/e495f1/32.png) [@perezb2022](https://community.postman.com/u/perezb2022)\
**Post date:** [February 14, 2023, 5:43pm UTC](https://community.postman.com/t/find-substring-extract-it-with-its-corresponding-value-from-string-source/43976/3 "2023-02-14T17:43:08Z")

</div>

Good day mdjones , as always thank you very much ,for your help
