I make a request to my script, in response I get such a picture

12345<style type="text/css"> 

And after that the hosting advertising went, I have nothing against it, but this prevents me from sparcing the answer. You need to parse everything from the beginning to < or <style .

I tried

 answer:gmatch("(%s+)(<)") 

In my opinion, it should look something like this, but it does not work.

  • More like a task and not a question, give an example of your code and what exactly you can’t do. - Vladimir Klykov
  • I tried differently, it doesn’t work at all - 33cc00
  • More like a task and not a question, give an example of your code and what exactly you can’t do - Vladimir Klykov
  • one
    answer: gmatch ("(% s +) (<)"), in my opinion it should look something like this, but it doesn't work - 33cc00 1:24 pm

2 answers 2

Instead of gmatch use match :

 local answer = [[12345<style type="text/css"><]] print( answer:match("(.-)<style") ) 

    The gmatch method gmatch for several matches, you need the first one. The template (%s+)(<) finds 1+ whitespace characters, then the < sign. Immediately you need to get the numbers to the first character < .

    I think the easiest way to get the first occurrence of one or more digits is with

     local a = [[12345<style type="text/css"><]] print(a:match("%d+")) 

    The %d+ pattern matches one or more digits, while match finds the first entry in the string.

    To find 1 or more characters other than < , use [^<]+ :

     local a = [[12345<style type="text/css"><]] print(a:match("[^<]+")) 

    See the online demo on Lua .