lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 5-Jul-07, at 9:49 AM, Patrick Donnelly wrote:

I'm trying to understand this error. I tried looking at the source, but it didn't help much. I'm getting this error as the result of looking for a word in a localized string.

I'm originally given a string similar to: "%s goes to %s". This is localized during startup, and it is formatted according to the situation. I receive the formatted string and would like to extract what each %s is. Thus I'm using captures. So I take "%s goes to %s" and format it:

local x = "Dave goes to Britain" -- Given to me

local y = string.format("%s goes to %s", "(%w*)", "(%w*)");

-- Then I get the captures:

local _, _, who, where = string.find(x, y);

print(who)
print(where)

My problem is this works fine for English, but when I use this for a German locale I receive the error: Invalid Capture Index. I'm really confused about what is going wrong here, mostly because I don't understand this error.

Perhaps the German format string has % codes in it? Sounds to me like
your compiled string pattern has an invalid back-reference or some such.