1. Dears,

    I meat the following codes but does not understand how to interpret the pattern.

     local leaderboardTxt, itemType, isDone = GetQuestLogLeaderBoard(k,i);
    
     local y, z, strObjDesc, intNumGot, intNumNeeded = string.find(leaderboardTxt, "(.\*):%s\*([%d]+)%s\*/%s\*([%d]+)");
    

    In the pattern "(.\*):%s\*([%d]+)%s\*/%s\*([%d]+)", I can only understand the meaning of "%s" to be a white space, but can't understand the rest characters, e.g. "(", ".", "*", "()", "%d" (represenets a digit, right?), "+". Does anybody can give a detailed explain?

    For example, the variable leaderboardTxt is "Kill foo: 0/10", how does it fit into the pattern?

    Many thx!

    Dears,

    I meat the following codes but does not understand how to interpret the pattern.

     local leaderboardTxt, itemType, isDone = GetQuestLogLeaderBoard(k,i);
    

    This just calls into an API function to get some information.

     local y, z, strObjDesc, intNumGot, intNumNeeded = string.find(leaderboardTxt, "(.\*):%s\*([%d]+)%s\*/%s\*([%d]+)");
    

    This pattern is just weird, they've escaped characters that don't need to be escaped. It may be easier to read if it is this:

     (.*):%s*([%d]+)%s*/%s*([%d]+)
    

    But even that is wrong, since [%d] is the same as %d and I'm fairly certain they don't mean %s/%s there, they mean %S/%S which is COMPLETELY different.

    So, you're trying to get the object description, the number we have and the number we want to obtain. The easiest pattern for this is the following:

     ^(.*): (%S+)/(%S+)
    

    That's all you need. Let's break that down:

    • ^ anchors the pattern so that it must appear at the front of the string. This is really just an optimization, but it makes it a bit quicker and more clear.
    • (.*): says to match (and capture, i.e. return) 0 or more repetitions of any character, followed by a :. This may not be the first : encountered, but in our pattern it should be the correct one because of the rest of the pattern.
    • (%S+) says to match and capture 1 or more repetitions of non-space characters. This could just as easily be (%d+), which is 'any numerical digits' and you may feel more comfortable with that one.
    • / is interpreted literally.

    So what we have is a pattern that matches the characters preceding the colon character (starting at the front of the string) that is followed by two non-space strings separated by a forward slash.

    Thank you very much for the detailed explanation. I'll test your pattern in my code.

    There are some my comments below.

    Dears,

    I meat the following codes but does not understand how to interpret the pattern.

     local leaderboardTxt, itemType, isDone = GetQuestLogLeaderBoard(k,i);
    

    This just calls into an API function to get some information.

     local y, z, strObjDesc, intNumGot, intNumNeeded = string.find(leaderboardTxt, "(.\*):%s\*([%d]+)%s\*/%s\*([%d]+)");
    

    This pattern is just weird, they've escaped characters that don't need to be escaped. It may be easier to read if it is this:

     (.*):%s*([%d]+)%s*/%s*([%d]+)
    

    I use the escape character to type "" character in the thread, because I found without the escape the "" could not be shown.

    But even that is wrong, since [%d] is the same as %d and I'm fairly certain they don't mean %s/%s there, they mean %S/%S which is COMPLETELY different.

    The pattern in my head thread is from the example of GetQuestLogLeaderBoard() API from wowwiki. That example use this pattern to interpret the quest objective. Is that wrong?

    So, you're trying to get the object description, the number we have and the number we want to obtain. The easiest pattern for this is the following:

     ^(.*): (%S+)/(%S+)
    

    That's all you need. Let's break that down:

    • ^ anchors the pattern so that it must appear at the front of the string. This is really just an optimization, but it makes it a bit quicker and more clear.
    • (.*): says to match (and capture, i.e. return) 0 or more repetitions of any character, followed by a :. This may not be the first : encountered, but in our pattern it should be the correct one because of the rest of the pattern.
    • (%S+) says to match and capture 1 or more repetitions of non-space characters. This could just as easily be (%d+), which is 'any numerical digits' and you may feel more comfortable with that one.
    • / is interpreted literally.

    So what we have is a pattern that matches the characters preceding the colon character (starting at the front of the string) that is followed by two non-space strings separated by a forward slash.

    But even that is wrong, since [%d] is the same as %d and I'm fairly certain they don't mean %s/%s there, they mean %S/%S which is COMPLETELY different.

    The pattern in my head thread is from the example of GetQuestLogLeaderBoard() API from wowwiki. That example use this pattern to interpret the quest objective. Is that wrong?

    [%d] is precisely the same as %d. You use [] to indicate a list of characters or character classes to match. For example [%d%a_] matches any digits, letters or the underscore, a single time. Its just unnecessary and fairly confusing, if all the other information is accurate.

    So, you're trying to get the object description, the number we have and the number we want to obtain. The easiest pattern for this is the following:

     ^(.*): (%S+)/(%S+)
    

    That's all you need. Let's break that down:

    • ^ anchors the pattern so that it must appear at the front of the string. This is really just an optimization, but it makes it a bit quicker and more clear.
    • (.*): says to match (and capture, i.e. return) 0 or more repetitions of any character, followed by a :. This may not be the first : encountered, but in our pattern it should be the correct one because of the rest of the pattern.
    • (%S+) says to match and capture 1 or more repetitions of non-space characters. This could just as easily be (%d+), which is 'any numerical digits' and you may feel more comfortable with that one.
    • / is interpreted literally.

    So what we have is a pattern that matches the characters preceding the colon character (starting at the front of the string) that is followed by two non-space strings separated by a forward slash.