Text-Glob-0.09 > Text::Glob

名前

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* matches a, aa, aaaa and many many more.

? - match exactly one character

a? matches aa, but not a, or aaa

Character sets/ranges

example.[ch] matches example.c and example.h

demo.[a-c] matches demo.a, demo.b, and demo.c

alternation

example.{foo,bar,baz} matches example.foo, example.bar, and example.baz

leading . must be explictly matched

*.foo does not match .bar.foo. For this you must either specify the leading . in the glob pattern (.*.foo), or set $Text::Glob::strict_leading_dot to a false value while compiling the regex.

* and ? do not match /

*.foo does not match bar/baz.foo. For this you must either explicitly match the / in the glob (*/*.foo), or set $Text::Glob::strict_wildcard_slash to a false value with compiling the regex.

関連するのは, 以下のメタ文字とルールになります.

* - 0以上の文字とのマッチ

a*a, aa, aaaaとその他たくさんのものとマッチします.

? - ただ一つの文字とのマッチ

a?aaにマッチしますが, aaaaにはマッチしません.

文字集合/範囲

example.[ch]example.cexample.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を偽の値を 設定した場合に得られる, コンパイル済み正規表現を使う必要があります.

*?は / にマッチしません

*.foobar/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)