6

I want to remove all text except for what's between quotation marks.

How would I go about doing that?

Example:

Bran could hear the wind in the trees, the clatter of their hooves on the ironwood planks, the whimpering of his hungry pup, but Jon was listening to something else. “There,” Jon said. He swung his horse around and galloped back across the bridge. They watched him dismount where the direwolf lay dead in the snow, watched him kneel. A moment later he was riding back to them, smiling. “He must have crawled away from the others,” Jon said. “Or been driven away,” their father said, looking at the sixth pup. His fur was white, where the rest of the litter was grey. His eyes were as red as the blood of the ragged man who had died that morning. Bran thought it curious that this pup alone would have opened his eyes while the others were still blind. “An albino,” Theon Greyjoy said with wry amusement. “This one will die even faster than the others.” Jon Snow gave his father’s ward a long, chilling look. “I think not, Greyjoy,” he said. “This one belongs to me.”

Needed result:

“There,” “He must have crawled away from the others,” “Or been driven away,” “An albino,” “This one will die even faster than the others.” “I think not, Greyjoy,” “This one belongs to me.”

Or

There, He must have crawled away from the others, Or been driven away, An albino, This one will die even faster than the others. I think not, Greyjoy, This one belongs to me.

2 Answers 2

3
  • Ctrl+H
  • Find what: (?:^|\G)[^“”]*(“[^”]*”)
  • Replace with: $1 (Note: there is a space before $1)
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

(?:^|\G)    : non capture group, beginning of line or posiiton of last match
[^“”]*      : 0 or more any character that is not “ or ”
(           : start group 1
    “       : opening “
    [^“”]*  : 0 or more any character that is not “ or ”
    ”       : closing ”
)           : end group

You may use “([^”]*)” instead of (“[^”]*”) if you don't want the quotes in the result.

Replacement:

 $1         : a space followed by content of group 1

Result for given example:

“There,” “He must have crawled away from the others,” “Or been driven away,” “An albino,” “This one will die even faster than the others.” “I think not, Greyjoy,” “This one belongs to me.”

1
  • Amazing answer. Thanks.
    – Zac
    Commented Apr 3, 2021 at 18:40
0

In CudaText editor, you can do it with multi-selections.

  • dialog Find, enter ".+?", check reg-ex option
  • press "Select all" in dialog
  • text inside quotes is selected, Copy to clipboard
  • make new file tab, Paste from clipboard

To join resulting lines to one, use CudaExt plugin's command "Join selected lines".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .