# Help regex function!

**URL:** <https://community.n8n.io/t/help-regex-function/21987>\
**Category:** Questions\
**Tags:** core, data-transformation, function, functionitem, n8n-node\
**Created:** [January 18, 2023, 12:44pm UTC](https://community.n8n.io/t/help-regex-function/21987 "2023-01-18T12:44:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![oly-dev](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/oly-dev/32/25710_2.png) [@oly-dev](https://community.n8n.io/u/oly-dev)\
**Post date:** [January 18, 2023, 12:44pm UTC](https://community.n8n.io/t/help-regex-function/21987/1 "2023-01-18T12:44:46Z")

</div>

## Describe the issue/error/question

Hi! im goingt crazy with what i thought was going to be aeasy thing. I have a string like this:

```auto
<https://cdn.shopify.com/s/files/1/0454/8182/0319/files/19795198-1_1.jpg>; rel="canonical"

```

I just wante to extract the URL , so i want the output to be:

```auto
https://cdn.shopify.com/s/files/1/0454/8182/0319/files/19795198-1_1.jpg

```

I have no idea about javascript, but ive researced for formula’s and it seems REGEX should do it, however i keep running into different errors and have no idea why … i attach a screenshot of the last error i got … is it because ITEM isn’t a string and the REGEX function only works on strings?

## What is the error message (if any)?

ERROR: Cannot convert undefined or null to object

##?SCREENSHOT

 ![Screenshot 2023-01-18 at 13.39.47](https://europe1.discourse-cdn.com/n8n/original/3X/8/d/8dec97ed723100d071c109df0d131c52cc2c8c1f.jpeg)

## Please share the workflow

## Share the output returned by the last node

## Information on your n8n setup

- **n8n version:**
- **Database you’re using (default: SQLite):**
- **Running n8n with the execution process [own(default), main]:**
- **Running n8n via [Docker, npm, n8n.cloud, desktop app]:**

---

<div class="post-metadata">

**Author:** ![dickhoning](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/dickhoning/32/10415_2.png) [@dickhoning](https://community.n8n.io/u/dickhoning)\
**Post date:** [January 21, 2023, 5:06am UTC](https://community.n8n.io/t/help-regex-function/21987/2 "2023-01-21T05:06:03Z")

</div>

Hi @oly-dev would this do the trick for you?

```auto
const url = items[0].json.url;

let start = url.indexOf("<");
let stop = url.indexOf(">");

let result = url.substring(start +1, stop);

return {"result": result}

```

---

<div class="post-metadata">

**Author:** ![chrisbol](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/chrisbol/32/21110_2.png) [@chrisbol](https://community.n8n.io/u/chrisbol)\
**Post date:** [January 21, 2023, 10:19am UTC](https://community.n8n.io/t/help-regex-function/21987/3 "2023-01-21T10:19:37Z")

</div>

continuing on answer by @dickhoning here an alternative with the Regex pattern.

> **const** url = items[0].json.url;  
> **let** result = url.match(“^\<([^\>]\*)”)[1];  
> **return** {“result”: result}

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [April 21, 2023, 10:20am UTC](https://community.n8n.io/t/help-regex-function/21987/4 "2023-04-21T10:20:09Z")

</div>

Closed on April 21, 2023, 10:20am UTC

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