Замените все "Но" Regex Notepad ++

1098
Lottex

У меня есть текстовый файл со строками, похожими на приведенные ниже: ('8510851205', 'needthishere', '', ''), он мне нужен, чтобы удалить все и оставить только эту потребность в каждой строке. Как бы я это сделал?

1
Для решения регулярных выражений мы узнаем очень конкретные подробности о том, в чем могут заключаться все форматы, «где это необходимо». Числа? Переносить (или другие знаки пунктуации) где-нибудь? Только буквы? Длина? Если достаточно другого типа ответа, вы можете просто заменить все ", \ s" на ", \ n", а затем поработать над магией (я могу объяснить больше в ответе, если это приемлемо) в результирующих строках. panhandel 10 лет назад 0
Иногда только буквы, иногда буквы с цифрами и длина всегда отличается Lottex 10 лет назад 0
Вот 2 примера ('2120986452', 'slthornton', '', ''), ('2121111111', 'strict_daddy4u', '', ''), я заметил, что это также может быть точка Lottex 10 лет назад 0

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

0
panhandel

Here is what I would do.

  1. Search for(Search mode: Regular Expression): .',\s' Replace with: \n
  2. In the find window, on the "Mark" tab, bookmark (checkbox) all lines with an apostrophe in them
  3. a)In the Search menu, choose Bookmark, then "Inverse Bookmark"
  4. a)At this point, you should have your two lines bookmarked; you can go back to the same Search -> Bookmark menu and cut/copy bookmarked lines

3b)In the search menu, choose "Remove Bookmarked Lines", which will leave only the two bits you are interested in

enter image description here

  1. enter image description here

  2. enter image description here

3b. enter image description here

0
zx81

Here is the simple regex you are looking for.

In N++, select the Replace tab in the Find window.Check the "Regular Expressions" box.

Find:

^[^)]*\('[^']*',\s*'([^']*)'(?:,\s*'')\),?\s*$ 

Replace:

\1 

Hit the "Replace All" button.

As an example, I ran this on this file:

('8510851205', 'needthishere', '', '') ('2120986452', 'slthornton', '', ''), ('2121111111', 'strict_daddy4u', '', '') 

The output:

needthishere slthornton strict_daddy4u 

I could have made it shorter, but wanted to make sure we matched the full set of four strings, just in case you have parentheses looking different. Please note that this specifically assumes that the third and fourth strings are empty. If you want to allow characters in those strings, use this instead:

^[^)]*\('[^']*',\s*'([^']*)'(?:,\s*'[^']*')\),?\s*$ 

Wishing you a great week!

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