283 posts
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?
227 posts
Location
Germany
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( "/%*(.-)%*\\" ) )
283 posts
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
355 posts
Location
Germany
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.
1426 posts
Location
Does anyone put something serious here?
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.