Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I make a string pattern that works for this format?

Asked by 4 years ago

Current Students:

AppleTreeFromNewYork

i have some text that looks like this, it can also look like this

Current Students:

AppleTreeFromNewYork,anotherstudent,thirdstudent

and i need a string pattern so i can get each student i have tried different ones to just get the 1 student but there can also be many students, this is the one i tried (.+)%s%s(.+) i just need help making a string pattern that can get all the students listed

0
yes i know this is formatted terribly, sorry about it Cald_fan 26 — 4y

1 answer

Log in to vote
0
Answered by
gskw 1046 Moderation Voter
4 years ago

For such a string pattern, you can use custom char-sets [sic]. Specifically, we will use the circumflex ^ at the beginning of the char-set definition to make it exclusive:

local students = "AppleTreeFromNewYork,anotherstudent,thirdstudent"
for student in students:gmatch("[^,]+") do -- Match strings containing as many non-commas as possible
    print(student)
end
0
the think is is that idk how to get the students Cald_fan 26 — 4y
0
because it looks like "Current Students:\n\nAppleTreeFromNewYork,anotherstudent,thirdstudent" and this looks bad because i cant space right here Cald_fan 26 — 4y
Ad

Answer this question