1

I have numerous SELECT statements conjoined by UNION keyword in a single file. What I want to do is to extract all the db.table strings only? How can I delete all words not containing period (.) using regex in notepad++ editor? Database and table are the only ones with a period.

It's okay with me even if new lines are not removed. Though, as a learning bonus for everyone seeing this post, you can also show the regex that trims the new lines, that will show this output:

db.table1
db.table2
...
db.tablen
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
oikonomiyaki
  • 7,691
  • 15
  • 62
  • 101

2 Answers2

2

You may try the following find and replace, in regex mode:

Find:    (?<=^|\s)[^.]+(?=$|\s)
Replace: <empty string>

Demo

Note that my replacement only removes the undesired terms in the query; it does not make an effort to remove stray or leftover whitespace. To do that, you can easily do a quick second replacement to remove whitespace you don't want.

Edit:

It appears that Notepad++ doesn't like the variable width lookbehinds I used in the pattern. Here is a refactored, and more verbose version, which uses strictly fixed width lookbehinds:

(^[^.]+$)|(^[^.]+(?=\s))|((?<=\s)[^.]+$)|((?<=\s)[^.]+(?=\s))

Demo

The logic in both of the above patterns is to match a word consisting entirely of non dot characters, which are surrounded on either side by one or more of the following:

  • start of the string (^)
  • end of the string ($)
  • any type of whitespace (\s)
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

My guess is that maybe this expression:

([\s\S]*?)(\S*(\.)\S*)

being replaced with $2\n or:

(\S*(\.)\S*)|(.+?)

with $1 might work.

Demo 1

Demo 2

Community
  • 1
  • 1
Emma
  • 27,428
  • 11
  • 44
  • 69