This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Piorjade's profile picture

Help me with this lua pattern

Started by Piorjade, 06 September 2017 - 12:40 PM
Piorjade #1
Posted 06 September 2017 - 02:40 PM
So I'm basically doing something with Love2D and when looking at a networking example the server script I saw that it basically searches for 2 coordinates in a message that the clients send.
The message looks like this:
"320 240"
And the server then tries to get the coordinates with this pattern:
"^(%-?[%d.e]*) (%-?[%d.e]*)$"

Sooo I get the the first bracket searches at the beginning and the second at the end and "%-?" means that it optionally searches for "-" (so "-320 -240" would work too)…. The only thing I don't get is [%d.e]

Well I know that %d means a digit but I don't get the ".e" part.
What does it mean?
KingofGamesYami #2
Posted 06 September 2017 - 02:57 PM
A bracketed statement (surrounded by []) is basically a new definition of a "filter" (such as %d). %d you know, ., within one of these things, is just that, a "." – meaning the pattern accepts decimals, and e (which is commonly used to mean *10^x).

Which means this is will be accepted:

1.235e3

Which is the same thing as 1.235 * 10^3, or 1235
Piorjade #3
Posted 06 September 2017 - 03:03 PM
Aah okay thank you :)/>