CurseForge and Overwolf are joining forces!
Awesome More Information
  • 0

    posted a message on Regular expressions make me cry.
    Quote from Phanx

    tags["<His/Her>"] = "His",
    tags["<his/hers>"] = "his", -- Proper sentence shouldn't start with this
    end

    for tag, word in pairs(tags) do
    text = text:gsub(tag, word)
    end
    [/code]

    Note that only practical variations of capitalizations are included; if the user is typing in ALL-CAPS like an idiot, their tags will be ignored, and words that are not grammatically correct at the beginning of a sentence are only included in lower-case. If you don't mind the (small) performance hit, you could add more capitalization variants to accomodate user error.


    This sounds like a lot more sophisticated way of doing it than what I do today.. as I already support all these tags I have four if's to go through but with your example it would be just one :)

    Question is I do want the users to type what they want.. if they want to capitalize all fine for me ;) .. is it not possible at all using regexp like [aA] with this?

    Quote from Phanx
    Also, you don't need to specifically address the possessive he's and she's, as the user should simply type <he/she>'s.


    Actually this works and has worked all the time with my current code :)

    Lilih
    Posted in: Lua Code Discussion
  • 0

    posted a message on Regular expressions make me cry.
    Quote from Xinhuan
    You problem lies with this line:

    local gender = string.match(txt,txt:gsub(txt,genderTable[UnitSex("player")]))

    specifically with the bolded part. You are taking the string txt, and substituting the string txt with genderTable[UnitSex("player")]. In english, this means you might as well have just typed this in your code:

    local gender = string.match(txt, genderTable[UnitSex("player")])

    The problem with
    txt:gsub(txt,genderTable[UnitSex("player")])
    is when txt contains special characters such as "Hello? Hi", it becomes

    ("Hello? Hi"):gsub("Hello? Hi", "She")

    The search string contains the special character "?" which means the letter o just before it is optional. It doesn't match at all, because of the "?" in the string being searched, nothing gets replaced, and you end up with

    local gender = string.match("Hello? Hi", "Hello? Hi")
    which will of course not match itself, and gender will be nil.


    Yey!:D Now the code works like a charm with as many magic chars I want :)

    Very much thanks!
    Posted in: Lua Code Discussion
  • 0

    posted a message on Regular expressions make me cry.
    Quote from Xinhuan
    Can you explain what you are trying to do with

    txt:gsub(txt, genderTable[UnitSex("player")])

    ?
    You seem to be searching and replacing itself with the genderTable string, but it will fail if the string contains any special characters such as ? . * - [ ] \ + ( and ).


    Hi:)

    Ok.. the reason Im doing it this way is because I have no idea what the string will be.. as it is made by the player ingame.

    I could receive a string where the tag <He/She> is the start of a sentence,
    while in another, the tag is in the middle of the sentence.. <he/she>

    Therefore to not be case-sensitive;

    example string1; txt = "<He/She> must be mad?"


    local gender = string.match(txt,txt:gsub(txt,genderTable[UnitSex("player")]))
    -- Gender = She
    txt = txt:gsub("<[hH][eE]/[sS][hH][eE]>", gender)
    -- Result txt = "She must be mad?"

    example string2; txt = "Is <he/she> mad?"
    Result txt = "Is she mad?"


    If I do the compare this way;

    local genderTable = { "[iI][tT]", "[hH][eE]", "[sS][hH][eE]" }
    txt = txt:gsub("<[hH][eE]/[sS][hH][eE]>", genderTable[UnitSex("player")])


    A string like "<He/She> must be mad?" would result in "[sS][hH][eE] must be mad?"


    I guess I'm doing something completely wrong here string compare wise :/
    Posted in: Lua Code Discussion
  • 0

    posted a message on Regular expressions make me cry.
    Quote from egingell
    What about this: "Is <he/she> ? That's just insane!"? (space before the question mark)


    Already tried that.. but the tag is still ignored :(

    And since this is strings the player is creating ingame I have no control if they format it like "<He/She>?" or "<He/She> ?"

    Lilih
    Posted in: Lua Code Discussion
  • 0

    posted a message on Regular expressions make me cry.
    Hi again:)

    What my addon basically does is;

    Players can edit quotes ingame and with these quotes they have some tags they can use.. like <he/she>, <him/her> etc. I also want this tags to be non case-sensitive.

    So if a user creates a quote "<He/She> likes to swim?" it echo's out correct.. i.e. "She likes to swim?" and if the user creates it like "Does <he/she> like to swim?" it also outputs correct.

    The tricky thing is if a user creates a quote like "Is <he/she>? That's just insane!" the tag is completly ignored and output is "Is <he/she>? That's just insane!" while it should have been "Is she? That's just insane!"

    If I use the example code from OrionShock my guess is tags wont be supported and also they're case-sensitive?

    Sorry for my dumb questions.. but I'm still a noob and learning every bit I can :)

    Lilih


    local genderTable = { "[iI][tT]", "[hH][eE]", "[sS][hH][eE]" }
    local gender = string.match(txt, txt:gsub(txt, genderTable[UnitSex("player")]))
    if gender ~= nil then txt = txt:gsub("<[hH][eE]/[sS][hH][eE]>", gender) gender = nil end

    genderTable = { "[iI][tT]'[sS]", "[hH][iI][mM]", "[hH][eE][rR]" }
    gender = string.match(txt, txt:gsub(txt, genderTable[UnitSex("player")]))
    if gender ~= nil then txt = txt:gsub("<[hH][iI][mM]/[hH][eE][rR]>", gender) gender = nil end

    genderTable = { "[iI][tT]'[sS]"], L["[hH][iI][sS]", "[hH][eE][rR]" }
    gender = string.match(txt, txt:gsub(txt, genderTable[UnitSex("player")]))
    if gender ~= nil then txt = txt:gsub("<[hH][iI][sS]/[hH][eE][rR]>", gender) gender = nil end
    Posted in: Lua Code Discussion
  • 0

    posted a message on Regular expressions make me cry.
    Hello everyone:)

    I'm rather new with LUA scripting and surely when it comes to regexp stuff..
    For a few days now I've struggled a bit with string.match and gsub

    "banging my head in the wall code";

    local genderTable = { "[iI][tT]", "[hH][eE]", "[sS][hH][eE]" }
    local gender = string.match(txt, txt:gsub(txt, genderTable[UnitSex("player")]))
    if gender ~= nil then txt = txt:gsub("<[hH][eE]/[sS][hH][eE]>", gender) gender = nil end

    So if I send the function the string;
    txt = "Why does <he/she>?"
    It works like a charm..

    But if the string is changed just a little bit;
    txt = "Is <he/she>? That's just crazy!"
    It doesn't work.. i.e <he/she> isnt converted to right gender..

    I guess it has to do with the ? and the fact its a magic character..?
    I really got no clue how to fix this... anyone know?:)

    Lilih @ The Venture Co. (EU)
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.