unix - Why wont the plus work properly with this sed command? -


i can't ([^/]+) sed regex work properly.
instead of returning non-forward slash characters, returns one.

command:

echo '/test/path/file.log' | sed -r 's|^.*([^/]+)/(.*)$|\1.\2|g' 

expected:

path.file.log 

result:

h.file.log 

also tried got same result:

echo '/test/path/file.log' | sed -r 's|^.*([^/]{1,})/(.*)$|\1.\2|g' 

the problem not [^/]+, preceding .*. .* greedy, , consume maximal amount of input. usual suggestion use .*? make non-greedy, posix regexes don't support syntax.

if there slash, add 1 regex stop consuming much.

$ echo '/test/path/file.log' | sed -r 's|^.*/([^/]+)/(.*)$|\1.\2|g' path.file.log 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -