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

patterns question

Started by KingofGamesYami, 20 May 2014 - 02:53 AM
KingofGamesYami #1
Posted 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?
theoriginalbit #2
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
KingofGamesYami #3
Posted 20 May 2014 - 05:29 AM
if you read this link, you'll find that - and * are both 0 or more repetitions, so it would be "%a*" or "%a-"
Thanks… I didn't remember that for some reason. probably because it was around 2 A.M. when I was reading it.
apemanzilla #4
Posted 20 May 2014 - 04:32 PM
You can use "or" in patterns? O.o
Lignum #5
Posted 20 May 2014 - 04:39 PM
You can use "or" in patterns? O.o
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.
Edited on 20 May 2014 - 02:39 PM
apemanzilla #6
Posted 20 May 2014 - 04:59 PM
You can use "or" in patterns? O.o
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.
Yes, that's what I thought… The OP used an "or" operand in their capture, so I wasn't sure.
Edited on 20 May 2014 - 02:59 PM
wieselkatze #7
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.
Wojbie #8
Posted 20 May 2014 - 10:15 PM
As far as I know you could just use (for an or) "[AB]" which would result in searching for A or B.
yea but thats on character level - you cant code it to look for "cat" or "dog"
KingofGamesYami #9
Posted 20 May 2014 - 10:29 PM
-snip-
Yes, that's what I thought… The OP used an "or" operand in their capture, so I wasn't sure.
I was simply stating two different ways of doing what I thought might work…
%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–