View Single Post
03-21-13, 11:19 AM   #41
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by F16Gaming View Post
So apparently a dash ('-') is equivalent to an asterisk ('*') in Lua patterns, not sure why you'd want to match 0 or more though.
A dash is not equivalent to an asterisk.

A plus sign matches at least once, but is greedy and will match as long a string as it can. It will keep going until the pattern no longer matches.

An asterisk is the same as a plus sign, except it can also match nothing.

A minus sign is lazy and matches the shortest string that fulfills the pattern. It stops as soon as it can, rather than continue after the first successful match like the plus sign.

Here's an example to demonstrate why they are very different:
Lua Code:
  1. > ("item:77272:0:0:0:0:0:0:0:11:0:0"):match("(.+):")
  2. item:77272:0:0:0:0:0:0:0:11:0
  3.  
  4. > ("item:77272:0:0:0:0:0:0:0:11:0:0"):match("(.*):")
  5. item:77272:0:0:0:0:0:0:0:11:0
  6.  
  7. > ("item:77272:0:0:0:0:0:0:0:11:0:0"):match("(.-):")
  8. item

Last edited by semlar : 03-21-13 at 11:22 AM.
  Reply With Quote