Class: NamedCaptureExtractor
Overview
NamedCaptureExtractor is a utility class for extracting named groups from regular expressions and converting them into symbol-keyed hashes for flexible pattern matching and data extraction.
Class Method Summary collapse
- .extract_named_group2(match_data) ⇒ Object
-
.extract_named_groups(str, pattern) ⇒ Hash<Symbol, String>?
Extracts named groups from a regex match on the given string, converting them into a symbol-keyed hash.
Class Method Details
.extract_named_group2(match_data) ⇒ Object
97 98 99 |
# File 'lib/markdown_exec.rb', line 97 def self.extract_named_group2(match_data) match_data&.named_captures&.transform_keys(&:to_sym) end |
.extract_named_groups(str, pattern) ⇒ Hash<Symbol, String>?
Extracts named groups from a regex match on the given string, converting them into a symbol-keyed hash.
93 94 95 96 |
# File 'lib/markdown_exec.rb', line 93 def self.extract_named_groups(str, pattern) regexp = pattern.is_a?(Regexp) ? pattern : Regexp.new(pattern) str&.match(regexp)&.named_captures&.transform_keys(&:to_sym) end |