Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

String Patterns

I'm really struggling with this.. I'm trying to get only the first 2 per line in the string printed but it doesn't work perfectly

local pattern = "(%w+)%s?(%w+).-%d+"
local get = [[Start	Tackle	Normal	Physical	50	100%	 35
Start	Harden	Normal	Status	?	?%	 30
Start	Headbutt	Normal	Physical	70	100%	 15]]

for level, move in get:gmatch(pattern) do
	print(level.." "..move)
end

Here is my output:

Start Tackle
10 0
Start Harden
Start Headbutt
10 0

It should only be

Start Tackle
Start Harden
Start Headbutt

2 answers

✓ Accepted answer

This is what you need to produce the results you want.

local pattern = "(%w+)%s?(%w+).-\n"
local get = [[Start Tackle  Normal  Physical    50  100%     35
Start Harden  Normal  Status  ?   ?%   30
Start Headbutt    Normal  Physical    70  100%     15
]]

for level, move in get:gmatch(pattern) do
    print(level.." "..move)
end

The output

Start Tackle
Start Harden
Start Headbutt

1 comment

0

oh thanks! I didn't know \n could be used in Lua!

the reason it does this is because it has digits to get rid of digits just change the pattern to this

pattern = "(%w+)%s?(%w+)"

if you use the %d then it will also include digits

3 comments

0

my output is Start Tackle Normal Physical 50 100 35 Start Harden Normal Statu s 30 Start Headbutt Normal Physical 70 10 0 1 5

0

the thing is i also dont know what this code is trying to accomplish maybe if you edit it up a bit and describe what each Integer is supposed to mean

0

I told you want I want though... I said I just want to print the first 2 values of each line of the string

This discussion is preserved as it was. New answers, comments, and votes are closed.