Как удалить весь текст, кроме того, что внутри кавычек?

453
Chibi

Я хочу удалить весь текст, кроме кавычек.

Как бы я поступил так?

Пример:

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.”

Необходимый результат:

“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.”

Или же

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

2 ответа на вопрос

0
RProgram

В редакторе CudaText вы можете сделать это с несколькими вариантами выбора.

  • диалог Найти, войти ".+?", проверить параметр рег-экс
  • нажмите «Выбрать все» в диалоговом окне
  • текст внутри кавычек выделен, Копировать в буфер
  • создать новую вкладку файла, вставить из буфера обмена

Чтобы объединить полученные строки в одну, используйте команду плагина CudaExt «Объединить выбранные строки».

0
Toto
  • Ctrl+H
  • Найти то, что: (?:^|\G)[^“”]*(“[^”]*”)
  • Заменить на: $1 ( Примечание: до этого есть пробел$1 )
  • проверить обернуть
  • проверьте регулярное выражение
  • Replace all

Объяснение:

(?:^|\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 

Вы можете использовать “([^”]*)”вместо, (“[^”]*”)если вы не хотите кавычки в результате.

Замена:

 $1 : a space followed by content of group 1 

Результат для данного примера:

«Там», «Должно быть, он отполз от других», «Или был изгнан», «Альбинос», «Этот умрет даже быстрее, чем другие». «Думаю, нет, Грейджой», «Этот принадлежит мне."

Похожие вопросы