0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

bashでマッチした部分だけを抽出する正規表現 Lv1

Posted at

簡単なコマンドのみ

コマンド

$ egrep -o '(.*extracted-character/)'

egrep は拡張grep
-o はマッチした部分だけ抽出する

実行例

$ pwd
/path/to/my-project-name/src/dir/

$ pwd | egrep -o '(.*my-project-name/)'
/path/to/my-project-name/

動機

ShellScript内で、プロジェクトルートのpathを取得する際に利用しました。

環境

  • macOS
  • zsh

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?