LoginSignup
0
1

More than 3 years have passed since last update.

grep コマンドの正規表現の Shorthand Character(\w など)

Last updated at Posted at 2018-01-16

こんにちは
grep コマンドの正規表現の Shorthand Character1 を調べました。

  • \w, \W (alphanumeric, non alphanumeric), \s, \S (space, non space) が使えます。
$ echo "a1" | grep -e "\w"
a1

Perl Regular Expression

Perl Regular Expression (-P) 2 では、さらに多種類の Shorthand Character が使えます(\d (numeric) など)。

$ echo "11" | grep -P "\d"
11
$ echo "11" | grep -e "\d"
$ echo "11" | grep -G "\d"
$ echo "11" | grep -E "\d"

繰り返し (Extened Regular Expression, Perl Regular Expression)

Extened Regular Expression (-E), Perl Regular Expression (-P) では、+(繰り返し)などが使えます。

$ echo "aa" | grep -E "a+"
aa
$ echo "aa" | grep -P "a+"
aa
$ echo "aa" | grep -e "a+"
$ echo "aa" | grep -G "a+"

  1. エスケープで始めるメタキャラクターです。 

  2. BSD grep では Perl Regular Expression (-P) を持っていないようです。 

0
1
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
1