This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Creeper9207's profile picture

Find text between phrases

Started by Creeper9207, 07 April 2015 - 08:01 PM
Creeper9207 #1
Posted 07 April 2015 - 10:01 PM
How can i find text between two phrases?
ex: <::hi::> (i want "hi"
Dragon53535 #2
Posted 07 April 2015 - 10:06 PM

for word in string.gmatch("<::hi::.hi...hi","%w") do
  print(word)
end
will print any words but not characters.
NanoBob #3
Posted 07 April 2015 - 10:18 PM
You could use a combination of the string.find() and string.sub() function to do this, finding the first occurence of "<::" and the first of "::>" and then with string.sub taking the parts in between. Information on these functions: http://lua-users.org/wiki/StringLibraryTutorial
Bomb Bloke #4
Posted 07 April 2015 - 10:39 PM
I think he's asking for something more like this kind of thing:

local myText = "<::hi::>"
print(string.match(myText, "<::(.-)::>"))

http://www.lua.org/pil/20.2.html
Edited on 07 April 2015 - 08:42 PM
Creeper9207 #5
Posted 08 April 2015 - 01:30 AM
thanks

i found pattern <::(/>.+)::> worked