How to find an url in a string

  1. What do you want to achieve? I want to find an url in a string to convert it to image or something

  2. What is the issue? no idea how to find an url in string.

  3. What solutions have you tried so far? i tried to find a solution on the forum but i couldnt find.

1 Like

thats not i wanted.

local msg = "hello example image:"

i want to find the in that string.

also i want to find any url not specially gyazo.

What are you trying to do exactly with the url? I don’t really understand.

i just want to set an imagelabel’s image url to the url
why im doing this:
i have an custom chat and i want players to send images by sending an link to chat

You would use String Patterns in order to achieve this.

1 Like

Images in image labels are exlusively assets (Assets | Documentation - Roblox Creator Hub). Roblox doesn’t allow just any image in any format to be pasted.


Those IDs are in place for moderation purposes, as allowing players and developers to send just about any image poses a great risk.

Now, as Quwanterz said already, string patterns. I’d probably allow http, https, and assetId formats. Here’s one way of searching.

local link = "HTTP protocol: further text"
local assetId = "Asset ID: rbxassetid://000000001 further text"

local first, last = link:find("")
print(string.sub(link, first, last))

local first, last = assetId:find("rbxassetid://(%d+)")
print(string.sub(assetId, first, last))
string.find(str: string, pattern: string, init: number?, plain: boolean?):
number, number
-- Found nothing? Return nil.
string.sub(str: string, firstChar: number, lastChar: number): string --> substring

% → escape character (escapes magic characters, like ?)
%d → digits (character class)
+ → match one or more of the character class (class modifier)


thanks it works now.

1 Like

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