LoginSignup
3
2

More than 5 years have passed since last update.

bashで正規表現matchしたものがBASH_REMATCH配列変数に格納される

Last updated at Posted at 2018-06-28

こういうshellがあったとして

rematch.sh
if [[ $1 =~ ^http://(.+)\.(.+) ]]; then
  echo "${BASH_REMATCH[1]}"
  echo "${BASH_REMATCH[2]}"
fi

実行するとこうなる

$ sh rematch.sh http://example.com
example
com

レビューで教えてもらってはじめて知った。便利ー。

3
2
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
3
2