View Single Post
02-10-10, 07:35 PM   #12
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by ArrchDK View Post
Info on gsub

The second argument ("([a-z]+)([A-Z][a-z]+)") looks for a lower case letter ([a-z]) followed by an uppercase letter ([A-Z]) followed by a lower case letter ([a-z]). So in the case of ThunderBluff, it would find "rBl" as the pattern. Something like LookingForGroup would find "gFo" and "rGr". It then substitutes it with the third argument ("%1 %2"). In this case, it is substituting the first letter (%1) and the second letter (%2), combined would be (%1%2) with (%1 %2); essentially adding a space inbetween them. So "rBl" becomes "r Bl" in the string, making "ThunderBluff" change to "Thunder Bluff"

I hope that's easier to understand than it is to explain =/
That's a better explanation than I could have given.

To be completely accurate, it's searching for a string of lowercase letters of length >=1 both before and after the single capital letter; but it's true that you don't really need that. Removing the + signs would make it behave exactly as described.

As it is, "ThunderBluff" yields one match: "hunderBluff", which in turn matches the subpatterns as "(hunder)(Bluff)" and therefore %1 == "hunder" and %2 == "Bluff", resulting in gsub replacing all instances of "hunderBluff" with "hunder Bluff", with a final result of "Thunder Bluff" since there's only one instance of that.

In any case, I think: "(%l)(%u)" would work just as well; but it doesn't really matter much.

Last edited by Akryn : 02-10-10 at 07:49 PM.
  Reply With Quote