I’m trying to run a code step to retrieve the prefix of a URL.
I’m getting this error: Screenshot by Lightshot . To clarify, I’m looking to retrieve the ‘htzone’ part.
Here’s my code:const url = {{$json.body.zendeskURL}};const urlObject = new URL(url);const p - Pastebin.com
Here’s the relevant part of the workflow: Screenshot by Lightshot
Information on your n8n setup
**n8n version: 0.228.2
Running on the cloud.
Hi @Tamir_Bashkin , welcome to the community. Your code has a few problems:
While you need to add {{}}
in other nodes to reference data, you don’t need to do this in the code node.
When using the mode Run Once for Each Item
the node expects you to return one JSON object only and not an error.
Our code node unfortunately can’t use the URL object.
The following should work (you might wanna check if the string is a valid URL before though):
1 Like
That works perfectly, thanks!
Can you also help me understand how I remove special characters and apply a regex at the same step?
I’d like to apply this regex: ([^0-9a-zA-Zא-תА-яЁё]+) to the latestComment property, and replace everything with a space character. Then return the updated string.
Thanks!
@Tamir_Bashkin not sure if I understood you correctly, but this should do it if I did
1 Like
system
Closed
September 10, 2023, 2:53pm
5
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.