Jump to content




welp...im dumb


  • You cannot reply to this topic
4 replies to this topic

#1 SpencerBeige

  • Members
  • 263 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?

#2 wieselkatze

  • Members
  • 221 posts
  • LocationGermany

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( "/%*(.-)%*\\" ) )


#3 SpencerBeige

  • Members
  • 263 posts

Posted 08 March 2015 - 01:54 AM

View Postwieselkatze, on 08 March 2015 - 01:32 AM, said:

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 by slow-coder, 08 March 2015 - 01:56 AM.


#4 InDieTasten

  • Members
  • 357 posts
  • LocationGermany

Posted 08 March 2015 - 11:55 AM

View Postslow-coder, on 08 March 2015 - 01:54 AM, said:

View Postwieselkatze, on 08 March 2015 - 01:32 AM, said:

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.

#5 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes 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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users