Thread Tools Display Modes
Prev Previous Post   Next Post Next
03-21-13, 11:19 AM   #30
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
 

WoWInterface » Developer Discussions » Lua/XML Help » H: Why XML and why LUA?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off