I have a block of text as a large string ( so I can just paste in all the questions ) , but I want to make flash cards, so each questions needs to be considered as ONE string, hence the use of gmatch to separate them, so I can create a GUI for each question. Since each of the question starts with a number and ends with the page number, I need to figure out the pattern that will return all text between those two numbers.
local str = [[ 1. Why have the earliest ritual jade discs (bi) been found in tombs? a. The Chinese believed that jade would absorb the person?s soul b. They served as payment for entrance into the afterlife c. The Chinese believed that jade preserved the body from decay d. The beasts on their rims were to protect the dead from demons Answer: c page 214 2. According to Chinese legend, what inspired Fu Xi?s invention of a pictographic writing system? a. Visions that came to him in a dream b. Random scratches he noticed on animal bones c. Constellations and bird and animal footprints d. Papyri left behind by seafaring Egyptians Answer: c page 214 ]] for i in string.gmatch(str,"%d*%d") do --> 1, 214 2, 214 but not the text inbetween print(i) end
No, the correct pattern would be
Pattern = "%d+.-%d+"
Your pattern is telling: Find 0 or more digits followed by 1 digit.
While mine tells: Find the shortest sequence of characters between two or more digits.