名前¶
Text::Glob - match globbing patterns against text
Text::Glob - グロビングパターンによるテキストマッチング
概要¶
use Text::Glob qw( match_glob glob_to_regex );
print "matched\n" if match_glob( "foo.*", "foo.bar" );
# prints foo.bar and foo.baz
my $regex = glob_to_regex( "foo.*" );
for ( qw( foo.bar foo.baz foo bar ) ) {
print "matched: $_\n" if /$regex/;
}
use Text::Glob qw( match_glob glob_to_regex );
print "matched\n" if match_glob( "foo.*", "foo.bar" );
# foo.barと foo.bazが表示されます.
my $regex = glob_to_regex( "foo.*" );
for ( qw( foo.bar foo.baz foo bar ) ) {
print "matched: $_\n" if /$regex/;
}
説明¶
Text::Glob implements glob(3) style matching that can be used to match against text, rather than fetching names from a filesystem. If you want to do full file globbing use the File::Glob module instead.
Routines¶
- match_glob( $glob, @things_to_test )
-
Returns the list of things which match the glob from the source list.
- glob_to_regex( $glob )
-
Returns a compiled regex which is the equivalent of the globbing pattern.
- glob_to_regex_string( $glob )
-
Returns a regex string which is the equivalent of the globbing pattern.
Text::Globはテキストとのマッチングで使用することができる glob(3)スタイルの マッチングを実装しています(ファイルシステムからファイル名を取得することより テキストとのマッチングに適しています). もし完全なファイルグロブを使いたい場合は File::Globモジュールを代わりに使ってください.
関数¶
- match_glob( $glob, @things_to_test )
-
入力として与えたリストで globとマッチした要素がリストとして返されます.
- glob_to_regex( $glob )
-
指定したグロビングパターンと等価なコンパイル済み正規表現が返されます.
- glob_to_regex_string( $glob )
-
指定したグロビングパターンと等価な文字列で表された正規表現が返ります.
SYNTAX¶
The following metacharacters and rules are respected.
*- match zero or more characters-
a*matchesa,aa,aaaaand many many more. ?- match exactly one character-
a?matchesaa, but nota, oraaa - Character sets/ranges
-
example.[ch]matchesexample.candexample.hdemo.[a-c]matchesdemo.a,demo.b, anddemo.c - alternation
-
example.{foo,bar,baz}matchesexample.foo,example.bar, andexample.baz - leading . must be explictly matched
-
*.foodoes not match.bar.foo. For this you must either specify the leading . in the glob pattern (.*.foo), or set$Text::Glob::strict_leading_dotto a false value while compiling the regex. *and?do not match /-
*.foodoes not matchbar/baz.foo. For this you must either explicitly match the / in the glob (*/*.foo), or set$Text::Glob::strict_wildcard_slashto a false value with compiling the regex.
関連するのは, 以下のメタ文字とルールになります.
*- 0以上の文字とのマッチ-
a*はa,aa,aaaaとその他たくさんのものとマッチします. ?- ただ一つの文字とのマッチ-
a?はaaにマッチしますが,aやaaaにはマッチしません. - 文字集合/範囲
-
example.[ch]はexample.cとexample.hにマッチします.demo.[a-c]はdemo.a,demo.b及びdemo.cにマッチします. - 選択子.
-
example.{foo,bar,baz}はexample.foo,example.bar及びexample.bazにマッチします. - 先頭の . は明示的にマッチさせる必要があります
-
*.fooは.bar.fooにマッチしません. このためグロブパターンに先頭の . を明示的に指定するか,$Text::Glob::strict_leading_dotを偽の値を 設定した場合に得られる, コンパイル済み正規表現を使う必要があります. *と?は / にマッチしません-
*.fooはbar/baz.fooにマッチしません. このため / を明示的に マッチさせるグロブ(*/*.foo)か,$Text::Glob::strict_wildcard_slashに 偽となる値を設定した場合に得られる, コンパイル済み正規表現を使う必要があります.
バグ¶
The code uses qr// to produce compiled regexes, therefore this module requires perl version 5.005_03 or newer.
コンパイル済みの正規表現を生成するために qw//を使っているため, このモジュールを使うにはバージョンが 5.005_03以上の perlが必要となります.
作者¶
Richard Clamp <richardc@unixbeard.net>
コピーライト¶
Copyright (C) 2002, 2003, 2006, 2007 Richard Clamp. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO¶
File::Glob, glob(3)