View Single Post
08/17/15, 04:10 PM   #5
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by merlight View Post
string.gsub has an optional max_replacements parameter, so atm I'm passing 1 to prevent multiple replacements.
Sorry I would have posted something sooner if I thought you needed a fix. I thought you were just reporting the bug. Specifying a max of 1 replacement seems to work or you could just remove the space then it can't match more than once and could only match the first word because it does use the anchor on the first match, so its not completely ignoring the anchor. Either seems to work. It looks like its acting more like a gmatch (although yes ^ doesn't work with that, I mean its) iterating though the string. When it finds the first match & makes a replacement it starts over from that point & counts that as the ^ anchor point.
Lua Code:
  1. -- Change "^(%l+) " to "^(%l+)"
  2. df("%q %d", string.gsub("une rune de puissance", "^(%l+)", {une="<une>", de="<de>"}))

EDIT:
Originally Posted by Sasky View Post
I wonder if it's consuming the input pattern as it matches. Something like:

First match of "une rune de puissance" is "une ".
It then tries to match against "rune de puissance", then "de puissance", etc.

If that's the case, you could get the space in a separate step.
Lua Code:
  1. string.gsub("une rune de puissance", "^(%l+)", {une="<une@>", de="<de@>"}):gsub("@> ",">",1)
Oh and it looks like sasky already posted that :P
But yes that was my conclusion to when I tested it.

Last edited by circonian : 08/17/15 at 04:24 PM.