This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
SpencerBeige's profile picture

welp...im dumb

Started by SpencerBeige, 07 March 2015 - 11:57 PM
SpencerBeige #1
Posted 08 March 2015 - 12:57 AM
well, im making a custom emulator and i was wondering, how to make a custom command?string.find would WORK but not as i was hoping. if im trying to find code in the middle of something like /*test*\ then i couldn't do this correctly. help?
wieselkatze #2
Posted 08 March 2015 - 01:32 AM
You're probably looking for string.match().
Take a look at patterns and the string library in general. The last link will definitely make things clearer.
Regarding "/*text*\" the pattern to get test would be relatively simple:


local a = "/*test*\\"

print( a:match( "/%*(.-)%*\\" ) )
SpencerBeige #3
Posted 08 March 2015 - 01:54 AM
You're probably looking for string.match().
Take a look at patterns and the string library in general. The last link will definitely make things clearer.
Regarding "/*text*\" the pattern to get test would be relatively simple:


local a = "/*test*\\"

print( a:match( "/%*(.-)%*\\" ) )
thx

edit: also, do you know of a pattern generator? i could figure it out if i wanted, but its still a bit hard…
Edited on 08 March 2015 - 12:56 AM
InDieTasten #4
Posted 08 March 2015 - 11:55 AM
You're probably looking for string.match().
Take a look at patterns and the string library in general. The last link will definitely make things clearer.
Regarding "/*text*\" the pattern to get test would be relatively simple:


local a = "/*test*\\"

print( a:match( "/%*(.-)%*\\" ) )
thx

edit: also, do you know of a pattern generator? i could figure it out if i wanted, but its still a bit hard…
Well, me myself haven't seen any generators for computercraft "regex", because it's limited. The patterns are somewhat like regex, for which there exist a lot of generators(one of my favorites). Unfortunately, a full implementation of regex in Lua was too much overhead for the language, as the implementation would've been twice as big as the rest of the standard libraries. But there actually do exist full implementations of regex inside Lua(a Google search once helped), if you want to use the full POSIX functionality of regex.
SquidDev #5
Posted 08 March 2015 - 12:01 PM
There is also a pure-lua implementation of LPeg which is an advanced implementation of Lua's pattern matching library. Its pretty powerful though potentially slow.