1 °³¿ä
·ç¾Æ¿¡¼µµ Á¤±Ô½ÄÀ» »ç¿ëÇÒ ¼ö ÀÖ±â´Â Çѵ¥, Perl, Python, Ruby °°ÀÌ º»°ÝÀû(?)ÀÎ ½ºÅ©¸³Æ® ¾ð¾îº¸´Ù´Â ±â´ÉÀÌ Á» ºó¾àÇÑ ÆíÀÌ´Ù.
2 °Ë»ö
string ¸ðµâÀÇ find ¶Ç´Â gmatch ÇÔ¼ö¸¦ ÀÌ¿ëÇÑ´Ù.
find ÇÔ¼ö´Â Á¤±Ô½Ä°ú ÀÏÄ¡ÇÏ´Â ºÎºÐÀÇ ½ÃÀÛ°ú ³¡ À妽º¸¦ ¹ÝȯÇÑ´Ù. Á¤±Ô½ÄÀÌ ±×·ìÈµÈ °ÍÀ̶ó¸é, ½ÃÀÛ°ú ³¡ À妽º ¿Ü¿¡µµ ÇØ´ç ¹®ÀÚ¿µµ ¹ÝȯÇÑ´Ù.
string.find (s, pattern [, init [, plain]])
local b1, e1, pattern = string.find("abcd12efgh", "[a-z]+")
print(b1, e1, pattern)
local b1, e1, pattern = string.find("abcd12efgh", "([a-z]+)")
print(b1, e1, pattern)
1 4 nil
1 4 abcd
gmatch ÇÔ¼ö´Â iterator ÇÔ¼ö¸¦ ¹ÝȯÇÑ´Ù. ÀÌ ÇÔ¼ö´Â È£ÃâÇÒ ¶§¸¶´Ù ´ÙÀ½À¸·Î ÀÏÄ¡ÇÏ´Â ¹®ÀÚ¿À» ¹ÝȯÇÑ´Ù.
string.gmatch (s, pattern)
s = "hello world from Lua"
for w in string.gmatch(s, "%a+") do
print(w)
end
hello
world
from
Lua
3 ġȯ
string ¸ðµâÀÇ gsub ÇÔ¼ö¸¦ ÀÌ¿ëÇÑ´Ù.
string.gsub (s, pattern, repl [, n])
print(string.gsub("hello world", "(%w+)", "%1 %1"))
print(string.gsub("hello world", "%w+", "%0 %0", 1))
print(string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1"))
hello hello world world 2
hello hello world 1
world hello Lua from 2
ƯÀÌÇÑ °ÍÀº ġȯÇÒ ´ë»ó(repl)À¸·Î ¹®ÀÚ¿ »Ó¸¸ ¾Æ´Ï¶ó, Å×À̺í, ÇÔ¼ö µîÀ» Àü´ÞÇÒ ¼öµµ ÀÖ´Ù´Â Á¡Àε¥, ÀÌ¿¡ °üÇÑ °ÍÀº ·ç¾Æ ¸Å´º¾óÀ» Âü°íÇÏ±æ ¹Ù¶õ´Ù.
4 ¸µÅ©
SeriousMoin v1 (koMoinMoin 1.0a4 Modified)