I would like to extract cc.cc from
/aa/bb/cc.cc
either from
cc.cc
as well.
Solution:
$ echo "/aa/bb/cc.cc" | perl -pe "s|(?:.*/)?([^/]*)|\1|"
cc.cc
$ echo "/aa/cc.cc" | perl -pe "s|(?:.*/)?([^/]*)|\1|"
cc.cc
$ echo "cc.cc" | perl -pe "s|(?:.*/)?([^/]*)|\1|"
cc.cc
Some explanation:
- ?: start non capturing group
- [^/] any character except slash
No comments:
Post a Comment