Jump to content




Find text between phrases


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

#1 Creeper9207

  • Members
  • 211 posts

Posted 07 April 2015 - 09:01 PM

How can i find text between two phrases?
ex: <::hi::> (i want "hi"

#2 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 07 April 2015 - 09:06 PM

for word in string.gmatch("<::hi::.hi...hi","%w") do
  print(word)
end
will print any words but not characters.

#3 NanoBob

  • Members
  • 102 posts

Posted 07 April 2015 - 09: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...LibraryTutorial

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 07 April 2015 - 09: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 by Bomb Bloke, 07 April 2015 - 09:42 PM.


#5 Creeper9207

  • Members
  • 211 posts

Posted 08 April 2015 - 12:30 AM

thanks

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





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users