How to find only chars, that are next to diferent char?

Hi,
I need to use str.find, but in way, that it will find only specified char, when its next to diferent chars. How to do it? (I think, it is some easy patern, but i really dont understand string patterns)

You can use this reference.

It is unclear what you are asking. could you provide an example of your expected result?

2 Likes

I saw it, but still idk how to use it.

Can you give us an example string, to see what input we would be getting

In sring β€œ= === = =” i want to get only position of β€œ=” and not of β€œ===”, but it can be split by any char, not just space.

There is a function called string.split(str, splitter), where str is the string you wanna split, and splitter is the character you wanna split according to, in your case above, " ", a space. "= === = =” would become a table, where the first index is β€œ=”, second is β€œ===”, and 3rd and 4th are β€œ=”. Just grab the first index.

Is this what you’re looking for? Or is there another corner case?

1 Like

As i saied, idk what char will be there (else i will find just " = ").

Just change the parameters to what character you want. Change the splitter parameter.

But idk what char will be there, its from text box.

Unfortunately string.split does not take string patterns so you will have to make your own function that does.

Anyways this goes through non-"=" characters:

local other = "=A===B=C="
for s in other:gmatch("[^=]") do
    
end
1 Like

I need to use find as i saied, split was @starmaq’s idea.

Why do you need to use find?

I have got quite complicated system, that is adding something as Arduino to my game, and this is just part of it (it worked, but today i added == to compare values, but i found here the problem).
So, if I understand, for find it will be β€œ[^=]=[^=]”?

find only finds one occurrence. Which is why I gave you the code to find all occurrences.

IK, but i am already using for loop and from parametr.

Now i found that i need the same with split. Example: I need to split this string β€œ123=7==5” in {β€œ123”,β€œ7==5”}

Do you mean the first instance of β€œ=”? There are 3 there. β€œ= xxx = =”. I’m not talking about the Xs, btw.

I already solved this by

_,ch = string.find(str,"[^"..char.."]"..char.."[^"..char.."]")
ch = ch+1

only problem is with the split function.