- AuthorPosts
- September 24, 2019 at 12:31 am #26200spirosParticipant
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]]September 24, 2019 at 5:39 am #26201DavidParticipantI don’t know if this will help you:
Find: (‘)(.+?)(’)
Replace: \J “\1”.replace(/‘/g,”[[“) + “\2″.replace(/, /g,”]],[[“) + “\3″.replace(/’/g,”]]”)
September 24, 2019 at 7:36 am #26202spirosParticipantThanks! 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,”]]”)September 24, 2019 at 1:19 pm #26203Mr KTParticipantThis 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
September 24, 2019 at 4:28 pm #26205DavidParticipantI guess you missed the first \ character in “replace” .Please see my screenshot. It’s \J ,instead of J.
September 25, 2019 at 12:20 am #26206spirosParticipantHi 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.
- AuthorPosts
- You must be logged in to reply to this topic.