2

I need some help. I'm trying to replace multiple keywords in notepad++. See example below:

Find all:

apple alpha anchor ants all am are

Replace with:

"apple" "alpha" "anchor" "ants" "all" "am" "are"

Is there a way to replace it in one go?

Gilles-Antoine Nys
  • 1,481
  • 16
  • 21
Zoe C
  • 21
  • 1

2 Answers2

1

Press Hotkey: Ctrl + H (Replace)

tab: Replace

Find what: ((\b[^\s]+\b)((?<=\.\w).)?)

Replace with: "$1"

Select searchmode: Regular expression

Replace all => DONE

UPDATE

((\b[^\s]+\b)((?<=\.\w).)?) Regular expression, you can find more information in Wiki, some good tutorial is here and here: this regex will select all "word" seperate by space or .

"$1"you can find more information about this symbol here, mean we replace each word with "" and put the selected word it the middle

Dang Nguyen
  • 1,209
  • 1
  • 17
  • 29
  • Thank you it did work! Can you explain the formula ((\b[^\s]+\b)((?<=\.\w).)?) and "$1"? Thank you so much.. – Zoe C Dec 01 '18 at 10:13
  • @ZoeC I did update my answer, for more information, you can visit those link I provided or you can extract keyword and do some google search for your self. – Dang Nguyen Dec 03 '18 at 01:31
  • Why are you using lookbehind? And word boundary? – Toto Dec 03 '18 at 10:52
1
  • Ctrl+H
  • Find what: \w+
  • Replace with: "$0"
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

\w+ # 1 or more word character (i.e. [a-zA-Z0-9_])
         you could use [a-z]+ instead of \w+ if you want only lowercases
                    or \S+ if you want to match any character that is not a space      

Replacement:

"   # a double quote
$0  # content of group 0, the whole match (i.e. the keyword)
"   # a double quote

Result for given example:

"apple" "alpha" "anchor" "ants" "all" "am" "are"
Toto
  • 89,455
  • 62
  • 89
  • 125