-
What do you want to achieve? I want to find an url in a string to convert it to image or something
-
What is the issue? no idea how to find an url in string.
-
What solutions have you tried so far? i tried to find a solution on the forum but i couldnt find.
thats not i wanted.
local msg = "hello example image: https://gyazo.com/example"
i want to find the https://gyazo.com/example 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
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: http://www.roblox.com/asset/?id=507767714 further text"
local assetId = "Asset ID: rbxassetid://000000001 further text"
local first, last = link:find("http://www.roblox.com/asset/%?id=(%d+)")
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.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.