diff --git a/lib/fluent/match.rb b/lib/fluent/match.rb index 2f3e7eb4e6..17122e07ef 100644 --- a/lib/fluent/match.rb +++ b/lib/fluent/match.rb @@ -33,6 +33,15 @@ def match(str) class GlobMatchPattern < MatchPattern def initialize(pat) + if pat.start_with?('/') + if pat.end_with?('/') + @regex = Regexp.new("\\A"+pat[1..-2]+"\\Z") + return + else + raise Fluent::ConfigError, "invalid match - regex" + end + end + stack = [] regex = [''] escape = false diff --git a/test/test_match.rb b/test/test_match.rb index 1dcf3c80eb..4272a5c8c3 100644 --- a/test/test_match.rb +++ b/test/test_match.rb @@ -101,6 +101,17 @@ def test_multi_pattern_or assert_or_not_match('a.b.** a.c', 'a.c.d') end + def test_regex_pattern + assert_glob_match('/a/', 'a') + assert_glob_not_match('/a/', 'abc') + assert_glob_match('/a.*/', 'abc') + assert_glob_not_match('/b.*/', 'abc') + assert_glob_match('/a\..*/', 'a.b.c') + assert_glob_not_match('/(?!a\.).*/', 'a.b.c') + assert_glob_not_match('/a\..*/', 'b.b.c') + assert_glob_match('/(?!a\.).*/', 'b.b.c') + end + #def test_character_class # assert_match('[a]', 'a') # assert_match('[ab]', 'a')