问题
Using Notepad++ and replace function, I tried to add a symbol "+" or "[" before each word of my list.
Example of list :
- blue car
- red car big
- red car small
- green car big
- green car small
I'm looking for the following result :
- +blue +car
- +red +car +small
- +red +car +big
- .. etc
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".
回答1:
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:
回答2:
(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 useReplace all
for once
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
来源:https://stackoverflow.com/questions/40614144/regular-expression-add-a-character-before-after-each-word