This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
patterns question
Started by KingofGamesYami, 20 May 2014 - 02:53 AMPosted 20 May 2014 - 04:53 AM
Is there any way to make a pattern that expects 0 or more characters? "%a+" accepts 1+, "%a?" accepts 0 or 1. Would I simply combine the two ("%a?+" or "%a+?")? Or would I simply have to make an extra elseif statement?
Posted 20 May 2014 - 05:21 AM
if you read this link, you'll find that - and * are both 0 or more repetitions, so it would be "%a*" or "%a-"
Edited on 20 May 2014 - 03:22 AM
Posted 20 May 2014 - 05:29 AM
Thanks… I didn't remember that for some reason. probably because it was around 2 A.M. when I was reading it.if you read this link, you'll find that - and * are both 0 or more repetitions, so it would be "%a*" or "%a-"
Posted 20 May 2014 - 04:32 PM
You can use "or" in patterns? O.o
Posted 20 May 2014 - 04:39 PM
No. In regexes you can do things like "(A|B)" which means "match the letter A or B" but there's nothing like it in Lua patterns sadly.You can use "or" in patterns? O.o
Edited on 20 May 2014 - 02:39 PM
Posted 20 May 2014 - 04:59 PM
Yes, that's what I thought… The OP used an "or" operand in their capture, so I wasn't sure.No. In regexes you can do things like "(A|B)" which means "match the letter A or B" but there's nothing like it in Lua patterns sadly.You can use "or" in patterns? O.o
Edited on 20 May 2014 - 02:59 PM
Posted 20 May 2014 - 09:42 PM
As far as I know you could just use (for an or) "[AB]" which would result in searching for A or B.
Posted 20 May 2014 - 10:15 PM
yea but thats on character level - you cant code it to look for "cat" or "dog"As far as I know you could just use (for an or) "[AB]" which would result in searching for A or B.
Posted 20 May 2014 - 10:29 PM
I was simply stating two different ways of doing what I thought might work…Yes, that's what I thought… The OP used an "or" operand in their capture, so I wasn't sure.-snip-
%a+? and %a?+
my logic:
%a+? would check for multiple characters, but they can be none because the entire statement has ? after it
%a?+ checks for one or more "maybe" space characters
–This is irrelevant I know what I'm using now–