Reputation: 13
i try to have a regular expresion which will change "dir1/dir2/"
to "dir1/dir3/"
only if dir2
is not tmp
, and if it is tmp
,I want it not to change and stay "dir1/tmp"
.
I think I need a lookahead regex but I cant manage.
Upvotes: 1
Views: 478
Reputation: 454922
You can use negative lookahead assertion to do the substitution only if there is not tmp
after /dir1
:
s#(dir1/)(?!tmp/)[^/]+#\1/dir3#;
Upvotes: 2
Reputation: 8895
You could use if statement before applying the s////.... check using m// if tmp is not there and then replace.
Upvotes: 2