Reputation: 536
I have text:
alpha/beta/gamma
alpbeta/gamma
alpha/beta/gamma
This is an example. Test1,Test2,Test3
alpha/beta/gamma
This is an example.
Test1,Test2,Test3
i want to add * to the end of each word between slashes (/), but vim don't found nothing by my pattern...
my command:
:%s/\/(.*?)\//*/g
result I want:
alpha/beta*/gamma
alpbeta/gamma
alpha/beta*/gamma
This is an example. Test1,Test2,Test3
alpha/beta*/gamma
This is an example.
Test1,Test2,Test3
Upvotes: 1
Views: 94
Reputation: 627292
You can use
:%s/\/[[:alpha:]]\+\ze\//&*/g
Or even
:%s/\/[^\/]*\ze\//&*/g
Here, the pattern is \/[[:alpha:]]\+\ze\/
:
\/[[:alpha:]]\+
- The consuming part: /
and then one or more letters[^\/]*
- zero or more chars other than /
\ze\/
- end of the text consumed and then a /
char must follow (as if it were a (?=\/)
positive lookahead in common NFA regular expressions).The replacement is &
that stands for the whole match value and a *
char.
The g
flag replaces all occurrences.
Upvotes: 2
Reputation: 3541
According to your example it looks like you want a *
before the last occurence of /
in the line.
I'd go for recording a macro that does $F/i*^VESCj
(where ^V
is CTRL+V and ESC
is ESC.
This means go to the end of the line, find the /
backwards, enter insert mode, type the *
, go back to normal mode, go down a line.
You can record this as a macro and play it back for the whole file with something like :%normal @x
(if you recorded on x
)
Upvotes: 0
Reputation: 196789
Vim uses its own regular expressions dialect, where:
*?
in .*?
is meaningless,As it stands, your pattern would match:
\/
,(
,.*
,?
,)
,\/
,which is nowhere to be found in your sample.
See :help perl-patterns
.
Upvotes: -1