[SOLVED] about regex

i know how to do?just wonder if there is a better way to make it

str = "The |quick| brown fox"

i wanna get strs with regex like this?change a little?please use Space as delimiter

str1 = "The"
str2 = "|quick|"
str3 = "brown"
str4 = "fox"

@firewolf - have you tried google as I suggested?

@se24vad thanks

@Ignatz thanks

I’m sure Google has lots of suggestions if you search for Lua regex words

local str = "The quick brown fox"
str:gsub("%w+", function(word)
	print(word)
end)

@sw24vad I didn’t know you could use a function as a parameter there! It wasn’t in the Lua documentation, where did you learn that?

@SkyTheCoder - this page covers it

http://lua-users.org/wiki/StringLibraryTutorial

If the replacement is a function, not a string, the arguments passed to the function are any captures that are made. If the function returns a string, the value returned is substituted back into the string.

> = string.gsub("Hello Lua user", "(%w+)", print)  -- print any words found
Hello
Lua
user
        3
> = string.gsub("Hello Lua user", "(%w+)", function(w) return string.len(w) end) -- replace with lengths
5 3 4   3
> = string.gsub("banana", "(a)", string.upper)     -- make all "a"s found uppercase
bAnAnA  3
> = string.gsub("banana", "(a)(n)", function(a,b) return b..a end) -- reverse any "an"s
bnanaa  2

change a little?please use Space as delimiter

try reading up about regex