I have a gsub function that gets the asset of a string in a require
e.g.
local str = "require(4236423642)" -- Random asset id
local assetId = str:match("require%((.*)%)")
-->> 4236423642
but when i return a table of functions and try this:
local str = "require(4236423642).new()" -- Random asset id
local assetId = str:match("require%((.*)%)")
-->> 4236423642).new(
How can I get every character until the first instance of the closing bracket appears? So it would return 4236423642
instead of 4236423642).new(
Doomcolp
(dxxmed)
June 2, 2023, 10:39pm
#2
Just replace
local assetId = str:match("require%((.*)%)")
With this:
local assetId = str:match("require%((%d+)%)")
Doomcolp
(dxxmed)
June 2, 2023, 10:44pm
#4
That’s strange. I pasted your code (and made some changes) and it worked for me.
1 Like
Oh its because my require function also uses strings so require('foo')
also works
How can i modify it to also allow string stuff
Doomcolp
(dxxmed)
June 2, 2023, 10:48pm
#6
Just simply do this:
local assetId = str:match("require%((%w+)%)")
Hope this helps you out!
1 Like
Sorry but that doesnt appear to work either
Doomcolp
(dxxmed)
June 2, 2023, 10:52pm
#8
Huh. Both those worked for me… maybe because the words aren’t spaced out and gsub doesn’t recognize them. I’ve ran into this was I was trying to make a Lexer in the past.
1 Like
Wdym the words arent spaced out?
Doomcolp
(dxxmed)
June 2, 2023, 10:54pm
#10
Like the words don’t have a space in between them, here’s what I mean (I kinda doubt this is the issue though:
-- Spaced out
require( 12345 )
-- NOT spaced out
require(12345)
1 Like
Puzzled3d
(Puzzled)
June 2, 2023, 10:56pm
#11
Instead of just using %w+
can you make a group for it? And then add '
and "
to the group? I’m not familiar with regex / string commands
Doomcolp
(dxxmed)
June 2, 2023, 10:58pm
#12
Not sure what you mean by “group” but here’s the documentation for the string pattern reference sheet if you wanna learn more:
1 Like
Puzzled3d
(Puzzled)
June 2, 2023, 11:03pm
#13
I did it with this pattern:
require%(([%w%s/\'\"]+)%)
Thanks for all the help
1 Like
system
(system)
Closed
June 16, 2023, 11:04pm
#14
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.