Hello!
I have a msgTxt, that comes from a previous module, and I want to send this msgTxt to GPT assistant BUT i need to get rid of all the links in the message firs. I want to make it by replacing links with text “URL”
What I do, is I use “replace” function, and regular expression.
Here is what I got now:
{{replace(12.msgTxt; “(https?|ftp)://(?:(?:[\w-]+.)+[a-zA-Z]{2,}|localhost|\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})(?::\d+)?(?:/[^\s])?(?:?[^#\s])?(?:#[^\s]*)?”; “URL”)}}
I also tried to use simplier regular expression:
{{replace(12.msgTxt; “(https?|ftp):\/\/[^\s]+”; “URL”)}}
I tried without “” as well:
{{replace(12.msgTxt; (https?|ftp):\/\/[^\s]+; “URL”)}}
And no option works. I tried to validate regex with chat gpt, and it says it is correct. Maybe the problem is somewere beyond regex?
Here is screenshot of how I use “replace” function while requesting OpenAI module:
Welcome to the Make community!
To do this, you can use the built-in function replace
—
{{ replace(text; search string; replacement string) }}
with this Pattern (regular expression):
/(?:(?:ht|f)tps?:)?\/\/[\S"]+?(?=[\\\s"])/g
e.g.: (paste this into the field)
{{replace(12.msgText; "/(?:(?:ht|f)tps?:)?\/\/[\S""]+?(?=[\\\s""])/g"; "URL")}}
Proof https://regex101.com/r/9RNZtd/1
For more information, the function’s documentation can be found in the Help Centre. You should also complete the tutorials in the Make Academy.
Hope this helps! Let me know if there are any further questions or issues.
— @samliew
P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.
1 Like
thanks for the suggestion @samliew 
I tweaked your regex a bit, because if a message consisted only with link it didn’t work, so I ended up with the following:
{{replace(12.msgTxt; “/(?:(?:ht|f)tps?:)?//\S+/”; “URL”)}}
and its work fine. Thanks!
2 Likes
No problem, glad I could help! If my answer has helped you, please leave a like on my post.
1. If anyone has a new question in the future, please start a new thread. This makes it easier for others with the same problem to search for the answers to specific questions, and you are more likely to receive help since newer questions are monitored closely.
2. The Make Community guidelines encourages users to try to mark helpful replies as solutions to help keep the Community organized.
This marks the topic as solved, so that:
- others can save time when catching up with the latest activity here, and
- allows others to quickly jump to the solution if they come across the same problem
To do this, simply click the checkbox at the bottom of the post that answers your question:

3. Don’t forget to like and bookmark this topic so you can get back to it easily in future!
Hope this helps! Let me know if there are any further questions or issues.
— @samliew
P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.
1 Like