Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #26200
    spiros
    Participant

    There are phrases in a line which are delimited by opening and closing quote, like the ones below. I am trying to find a regex that would match the word/phrase with the comma as internal delimiter (or the whole externally delimited content if there is no comma as in the case of a single word/phrase). For example for these phrases:

    ‘verdichten’
    ‘verdichten, verstopfen’
    ‘dunkel, finster, wolkig’
    ‘fort sein, verloren sein, verloren’
    ‘von den Nymph ergriffen, verzückt, verrückt’
    ‘der sich halten kann, halten kann’

    The result I would like would be:

    [[verdichten]]
    [[verdichten]], [[verstopfen]]
    [[dunkel]], [[finster]], [[wolkig]]
    [[fort sein]], [[verloren sein]], [[verloren]]
    [[von den Nymph ergriffen]], [[verzückt]], [[verrückt]]
    [[der sich halten kann]], [[halten kann]]

    #26201
    David
    Participant

    I don’t know if this will help you:
    Find: (‘)(.+?)(’)
    Replace: \J “\1”.replace(/‘/g,”[[“) + “\2″.replace(/, /g,”]],[[“) + “\3″.replace(/’/g,”]]”)
    image

    #26202
    spiros
    Participant

    Thanks! This is what I got as output (with regular expression on):

    J “‘”.replace(/‘/g,”[[“) + “verdichten″.replace(/, /g,”]],[[“) + “’″.replace(/’/g,”]]”)
    J “‘”.replace(/‘/g,”[[“) + “verdichten, verstopfen″.replace(/, /g,”]],[[“) + “’″.replace(/’/g,”]]”)
    J “‘”.replace(/‘/g,”[[“) + “dunkel, finster, wolkig″.replace(/, /g,”]],[[“) + “’″.replace(/’/g,”]]”)
    J “‘”.replace(/‘/g,”[[“) + “fort sein, verloren sein, verloren″.replace(/, /g,”]],[[“) + “’″.replace(/’/g,”]]”)
    J “‘”.replace(/‘/g,”[[“) + “von den Nymph ergriffen, verzückt, verrückt″.replace(/, /g,”]],[[“) + “’″.replace(/’/g,”]]”)
    J “‘”.replace(/‘/g,”[[“) + “der sich halten kann, halten kann″.replace(/, /g,”]],[[“) + “’″.replace(/’/g,”]]”)

    #26203
    Mr KT
    Participant

    This works for me (using version 19.1 which supports named groups):
    Find:
    ((?<=^)|(?<=, ))‘?(?<word_or_phrase>[^‘,’]+)’?
    Replace:
    [[\k<word_or_phrase>]]

    One of 2 possible positive lookbehinds, followed by your potential opening quote, then capture your word/phrase (which can’t include quotes or comma), check for potential closing quote

    #26205
    David
    Participant

    I guess you missed the first \ character in “replace” .Please see my screenshot. It’s \J ,instead of J.

    #26206
    spiros
    Participant

    Hi David, no I did not miss it… strange.

    The 1st solution mentioned here seemed to work even in older versions: https://stackoverflow.com/questions/58084119/match-strings-between-delimiting-characters
    Did not test Mr KT’s solution as my version is older.

    Thank you very much both.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.