ディレクトリパスやアドレスの最後のディレクトリ名を取得
最後にマッチした以降のデータ取得
powershellで正規表現に一致した文字列を取得
カレントディレクトリ名を取得する4つの方法
タグ
■その1
$urls = @"
E:\Pictures\EOS D30\100CANON
E:\Pictures\EOS D30\110CANON
E:\Pictures\EOS D30\114CANON
"@
$pat = ".*\\([^\\]+)\\([^\\]+)$"
$regex = [regex]$pat
$regex.Matches($urls) | foreach {
$_.Groups[1].Value + "," + $_.Groups[2].Value
}
■その2
my $S = 'D:\PROGRAM\ANALYZE\LAN\data0123.dat';
## 正規表現
$S =~ m/.*\\([^\\]+)$/;
print $1;
■その3
$urls = @"
http://blog.livedoor.jp/morituri/archives/54111954.html
http://blog.livedoor.jp/morituri/archives/54105843.html
"@
$pat = "archives/([^/]+\.html)"
$regex = [regex]$pat
$regex.Matches($urls) | foreach {
$_.Groups[1].Value
}
・出力結果
54111954.html
54105843.html
■その4
cd /home/smith/music
pwd | sed 's,^\(.*/\)\?\([^/]*\),\2,'
music
■その5
<a.*?>(.*?)</a> 後方参照 $1