Jump to content




patterns question


  • You cannot reply to this topic
8 replies to this topic

#1 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 20 May 2014 - 03: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?

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 May 2014 - 04: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 by theoriginalbit, 20 May 2014 - 04:22 AM.


#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 20 May 2014 - 04:29 AM

View Posttheoriginalbit, on 20 May 2014 - 04:21 AM, said:

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.

#4 apemanzilla

  • Members
  • 1,421 posts

Posted 20 May 2014 - 03:32 PM

You can use "or" in patterns? O.o

#5 Lignum

  • Members
  • 558 posts

Posted 20 May 2014 - 03:39 PM

View Postapemanzilla, on 20 May 2014 - 03:32 PM, said:

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 by Lignum, 20 May 2014 - 03:39 PM.


#6 apemanzilla

  • Members
  • 1,421 posts

Posted 20 May 2014 - 03:59 PM

View PostLignum, on 20 May 2014 - 03:39 PM, said:

View Postapemanzilla, on 20 May 2014 - 03:32 PM, said:

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 by apemanzilla, 20 May 2014 - 03:59 PM.


#7 wieselkatze

  • Members
  • 221 posts
  • LocationGermany

Posted 20 May 2014 - 08:42 PM

As far as I know you could just use (for an or) "[AB]" which would result in searching for A or B.

#8 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 20 May 2014 - 09:15 PM

View Postwieselkatze, on 20 May 2014 - 08:42 PM, said:

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"

#9 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 20 May 2014 - 09:29 PM

View Postapemanzilla, on 20 May 2014 - 03:59 PM, said:

View PostLignum, on 20 May 2014 - 03:39 PM, said:

-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--





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users