2

I have a text file with lines looking like the one below : ('8510851205', 'needthishere', '', ''), I need it to remove everything and leave only needthishere on every single line. How would I do this :?

Lottex
  • 21

2 Answers2

0

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

panhandel
  • 2,554
0

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*''){2}\),?\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*'[^']*'){2}\),?\s*$

Wishing you a great week!

zx81
  • 458