{"record":{"id":"dca4328a9535af86","repo":"fluent/fluentd","slug":"invalid-regexp-formats-e","errorCode":null,"errorMessage":"Invalid regexp '#{formats}': #{e}","messagePattern":"Invalid regexp '#(.+?)': #(.+?)","errorType":"exception","errorClass":"Fluent::ConfigError","httpStatus":null,"severity":"error","filePath":"lib/fluent/plugin/parser_multiline.rb","lineNumber":67,"sourceCode":"          yield(time, record)\n          m\n        end\n      end\n\n      def configure(conf)\n        super\n\n        formats = parse_formats(conf).compact.map { |f| f[1..-2] }.join\n        begin\n          regexp = Regexp.new(formats, Regexp::MULTILINE)\n          if regexp.named_captures.empty?\n            raise \"No named captures\"\n          end\n          regexp_conf = Fluent::Config::Element.new(\"\", \"\", { \"expression\" => \"/#{formats}/m\" }, [])\n          @parser = Fluent::Plugin::MultilineParser::MultilineRegexpParser.new\n          @parser.configure(conf + regexp_conf)\n        rescue => e\n          raise Fluent::ConfigError, \"Invalid regexp '#{formats}': #{e}\"\n        end\n\n        if @format_firstline\n          check_format_regexp(@format_firstline, 'format_firstline')\n          @firstline_regex = Regexp.new(@format_firstline[1..-2])\n        end\n      end\n\n      def parse(text, &block)\n        loop do\n          m =\n            if @unmatched_lines\n              @parser.call(text) do |time, record|\n                if time && record\n                  yield(time, record)\n                else\n                  yield(Fluent::EventTime.now, { 'unmatched_line' => text })\n                end","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/fluent/fluentd/blob/dd45c6e18dc7be33b5e5a0f0767bf46307ff5626/lib/fluent/plugin/parser_multiline.rb#L49-L85","documentation":"MultilineParser#configure (lib/fluent/plugin/parser_multiline.rb:67) joins the format1..formatN regexes and compiles the combined expression; any failure is re-raised as Fluent::ConfigError with the joined source. Two distinct causes land here: the regex body is syntactically invalid (RegexpError from Regexp.new), or the manual 'No named captures' raise fires because the combined regexp has zero named capture groups. Both abort configuration.","triggerScenarios":"format1 /(?<log>\\w+)/ format2 /(?<tail>\\s+.*)/ with an unbalanced paren or stray '*' in one of them; multi-line Java stack-trace formats where every formatN uses numbered captures () instead of named (?<x>...); format strings containing raw '/' that breaks the /.../ delimiters after [1..-2] stripping.","commonSituations":"Configuring in_tail multiline parsing for Java/MySQL log formats; converting old fluentd v0 'format_firstline /.../' recipes to the format1..format20 scheme; escaping errors when porting regexes from other tools (double-escaping \\d in config files).","solutions":["Ensure the combined regex compiles: test with ruby -e \"Regexp.new(ARGV.join, Regexp::MULTILINE)\" using the stripped bodies.","Include at least one named capture group like (?<message>.*) across the formatN set.","Validate the whole config with fluentd --dry-run before deploying.","Check Ruby (not PCRE/grep) regex syntax: named groups use (?<name>...), and backslashes must survive config parsing."],"exampleFix":"# before\nformat1 /^\\d{4}/   # no named capture -> 'No named captures'\nformat2 /\\s+.*/\n# after\nformat1 /(?<time>^\\d{4}-\\d{2}-\\d{2})/\nformat2 /(?<message>\\s+.*)/","handlingStrategy":"validation","validationCode":"# pre-deploy: verify combined multiline regex compiles and has named captures\nbodies = %w[format1_body format2_body] # paste stripped bodies here\njoined = bodies.join\nRegexp.new(joined, Regexp::MULTILINE)\nabort 'no named captures' if Regexp.new(joined, Regexp::MULTILINE).named_captures.empty?","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include at least one (?<name>...) group in the formatN set.","Test each regex in an interactive Ruby shell with Regexp::MULTILINE.","Dry-run the config after touching format lines.","Escape for both config parsing and Ruby regex (double backslashes where needed)."],"tags":["fluentd","multiline-parser","config-error","regex"],"backgroundTag":"invalid-regex-in-config","analyzedSha":"dd45c6e18dc7be33b5e5a0f0767bf46307ff5626","analyzedAt":"2026-08-21T16:22:07.332Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}