1

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 :?

  • For a regex solution, we're going to know very specific details about what all formats 'needthishere' can be in. Numbers? Hyphenated (or other punctuation) anywhere? Only letters? Length? If another type of answer suffices, you could just replace all ",\s" with ",\n" and then work some magic (I can explain more in an answer if this is acceptable) on the resulting lines. – panhandel Apr 13 '14 at 0:10
  • Sometimes only letters, sometimes letters with numbers and the length is always different – Lottex Apr 13 '14 at 0:14
  • Here are 2 examples ('2120986452', 'slthornton', '', ''), ('2121111111', 'strict_daddy4u', '', ''), I've noticed it could also be a dot – Lottex Apr 13 '14 at 11:14
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

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.