# Regex: Extracting data from string

**URL:** <https://community.parabola.io/t/regex-extracting-data-from-string/1900>\
**Category:** Ask a question\
**Created:** [June 30, 2021, 6:46pm UTC](https://community.parabola.io/t/regex-extracting-data-from-string/1900 "2021-06-30T18:46:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noah\_Orr](https://sea2.discourse-cdn.com/flex020/user_avatar/community.parabola.io/noah_orr/32/1485_2.png) [@Noah\_Orr](https://community.parabola.io/u/Noah_Orr)\
**Post date:** [June 30, 2021, 6:46pm UTC](https://community.parabola.io/t/regex-extracting-data-from-string/1900/1 "2021-06-30T18:46:20Z")

</div>

I am trying to extract data from a string using regex and have that extracted data become the value of the new column.

I have read through [https://parabola.io/transform/use-regex](https://parabola.io/transform/use-regex) and many Q&A from the community, but cant quite find the answer to my problem.

The string is a URL  
_Example:_ `https://www.test.com/item-name-t3-2?source=twi&medium=twi%6tFeed&campaign=WM+-+6%36+YAY+Targeting+4.3+%e6%8b&content=93746788475070651&ad_id=6384778084577065&twiid=PBCa8s4MYMdOFo1zYcHMKUXRaXFh6Zkhq%5fBuvlHPLnZbfI6Y%5em`

My expression works on the site: [https://regexr.com/](https://regexr.com/)  
_My Expression:_ `(?<=ad_id=)\d*|(?=&)`  
Which would result in capturing the ad\_id `6384778084577065`

**The Problem:**  
When I make my regex call it is just removing the ad\_id from the url and inserting the new url as the value for the new column.

_URL Column=_ `https://www.test.com/item-name-t3-2?source=twi&medium=twi%6tFeed&campaign=WM+-+6%36+YAY+Targeting+4.3+%e6%8b&content=93746788475070651&ad_id=6384778084577065&twiid=PBCa8s4MYMdOFo1zYcHMKUXRaXFh6Zkhq%5fBuvlHPLnZbfI6Y%5em`

_NEW Column =_ `https://www.test.com/item-name-t3-2?source=twi&medium=twi%6tFeed&campaign=WM+-+6%36+YAY+Targeting+4.3+%e6%8b&content=93746788475070651&ad_id=&twiid=PBCa8s4MYMdOFo1zYcHMKUXRaXFh6Zkhq%5fBuvlHPLnZbfI6Y%5em`

I am wanting the NEW column to be: `6384778084577065` and if no ad\_id is found leave column blank

 ![image](https://us1.discourse-cdn.com/flex020/uploads/parabola/original/2X/1/132e976c6bd6c4e5fad9d532acaa449bdef531cf.png)

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex020/user_avatar/community.parabola.io/daniel/32/732_2.png) [@daniel](https://community.parabola.io/u/daniel)\
**Post date:** [June 30, 2021, 10:01pm UTC](https://community.parabola.io/t/regex-extracting-data-from-string/1900/2 "2021-06-30T22:01:13Z")

</div>

Hi @Noah_Orr,

Welcome to the community 👋

The easiest way to go about this is to use the “Use regex” step and the “Extract text from column” step. This should work nicely if your URL parameters are separated by `&`.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/parabola/original/2X/2/245dc8d1b50c17b0e4591cddd98f2249deab7c01.png)

Start by using the regex expression `(.*)ad_id=`. This will capture everything up until the `ad_id` value.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/parabola/original/2X/5/56913c4de5d94177401a707fccf4081691815bbc.png)

Next, we can extract all characters before the first instance of `&` into a new column.

 ![Screen Shot 2021-06-30 at 2.58.49 PM](https://us1.discourse-cdn.com/flex020/uploads/parabola/original/2X/7/77ccb59ca6fabbce8cf8baf0aa59d7e7a90927ee.png)

This should work for all URLs following that format. If a URL does not contain an `ad_id`, the final column will remain blank.

Let me know if that helps!

---

<div class="post-metadata">

**Author:** ![Noah\_Orr](https://sea2.discourse-cdn.com/flex020/user_avatar/community.parabola.io/noah_orr/32/1485_2.png) [@Noah\_Orr](https://community.parabola.io/u/Noah_Orr)\
**Post date:** [June 30, 2021, 11:10pm UTC](https://community.parabola.io/t/regex-extracting-data-from-string/1900/3 "2021-06-30T23:10:20Z")

</div>

Got it! Thank you for the help!

It looks like you don’t need to use regex, you can simply use “Extract text from column” twice.

On the first extract to remove the first part of the URL (Everything before the ad\_id).  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/parabola/original/2X/2/2396ea0d781398ab8cbb60cfb7980d80b4d69bb1.png)  
Which will return: `6384778084577065&twiid=PBCa8s4MYMdOFo1zYcHMKUXRaXFh6Zkhq%5fBuvlHPLnZbfI6Y%5em`

and on the second extract you remove everything after the ad\_id.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/parabola/original/2X/1/1cedd5e38e51966bd00630038e79786272acc7ff.png)

Which returns: `6384778084577065`

I am not sure if that will affect performance, but for someone reading this solution and doesnt understand regex very well. This is an easier solution.
