Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

[Lua] Capturing all captures

Name: Anonymous 2006-11-26 22:36

Quick q. How did I get table w/ all captures from string.match() ?

Currently I use something like this:
    c1, c2, c3 = string.match(s, pattern)
    captures = { ["\\1"] = c1, ["\\2"] = c2, ["\\3"] = c3 }
Obviously, this is not how it should be.

Name: Anonymous 2006-11-29 20:35

I'm not sure quite why you're using stuff like ["\\1"] as indices, but if you can deal with numerical indices, you can make it more concise like so:
captures = { string.match(s, pattern) }
In case you were curious, the opposite of this operation is the function unpack, which returns multiple arguments according to the array passed to it:
string.match(unpack( { s, pattern } ))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List