B4b4j1
B4b4j1

Reputation: 460

Regular Expression - Add a character before/after each word

Using Notepad++ and replace function, I tried to add a symbol "+" or "[" before each word of my list.

Example of list :

I'm looking for the following result :

I know how to add a character befor each line... but I cannot find the way to add it in front of every word without using replace "blue" to "+blue".

Upvotes: 4

Views: 26413

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626748

A cross platform solution should be

Search: \b\w+\b (or \b[[:alpha:]]+\b)
Replace: +$&

Search pattern details:

  • \b - a leading word boundary
  • \w+ - 1 or more word chars (if [[:alpha:]]+ is used, 1+ letters)
  • \b - a trailing word boundary

Replacement details: + is a literal plus, and $& is the backreference to the whole match.

See the screenshot:

enter image description here

Upvotes: 10

arhak
arhak

Reputation: 2542

(see screenshot below)

  • open the Find/Replace dialog (Ctrt+H)
  • in the Find input, enter this regex: (\b\w) which means "word boundary followed by a letter"
  • in the Replace with input, enter this replacement: +\1 which means "put a + sign followed by whatever was matched between the regex parenthesis"
  • click Show advanced options checkbox
  • click Search with regular expressions radio button
  • then hit Replace button as many times as you want, or use Replace all for once

enter image description here

EDIT: for Windows is pretty much the same (see the find/replace dialog http://sqlblog.com/blogs/jamie_thomson/image_1AFC2B61.png) the Regular Expression option is at the bottom left

Upvotes: 2

Related Questions