Formatron v0.4.2
Formatron empowers everyone to control the output format of language models with minimal overhead.
Loading...
Searching...
No Matches
formatron.formats.regex.RegexExtractor Class Reference

An extractor that extracts a string using a regular expression. More...

Inheritance diagram for formatron.formats.regex.RegexExtractor:
formatron.extractor.NonterminalExtractor formatron.extractor.Extractor

Public Member Functions

 __init__ (self, str regex, str capture_name, str nonterminal)
 Initialize the regex extractor.
 
typing.Optional[tuple[str, re.Match|None]] extract (self, str input_str)
 Extract the string using the regular expression.
 
- Public Member Functions inherited from formatron.extractor.NonterminalExtractor
str nonterminal (self)
 Get the nonterminal of the extractor.
 
str kbnf_reference (self)
 
- Public Member Functions inherited from formatron.extractor.Extractor
 __str__ (self)
 
typing.Optional[str] capture_name (self)
 Get the name of the capture, or None if the extractor does not capture.
 

Protected Attributes

 _regex
 
- Protected Attributes inherited from formatron.extractor.NonterminalExtractor
 _nonterminal
 
- Protected Attributes inherited from formatron.extractor.Extractor
 _capture_name
 

Properties

str kbnf_definition (self)
 

Detailed Description

An extractor that extracts a string using a regular expression.

Definition at line 13 of file regex.py.

Constructor & Destructor Documentation

◆ __init__()

formatron.formats.regex.RegexExtractor.__init__ ( self,
str regex,
str capture_name,
str nonterminal )

Initialize the regex extractor.

Parameters
regexThe regular expression for extraction.
capture_nameThe name of the capture, or None if the extractor does not capture.
nonterminalThe nonterminal representing the extractor.

Reimplemented from formatron.extractor.NonterminalExtractor.

Definition at line 23 of file regex.py.

Member Function Documentation

◆ extract()

typing.Optional[tuple[str, re.Match | None]] formatron.formats.regex.RegexExtractor.extract ( self,
str input_str )

Extract the string using the regular expression.

Specifically, the first match(if any) of the regex pattern in the input string is returned.

Parameters
input_strThe input string.
Returns
The remaining string and the extracted re.Match object, or None if the extraction failed.

Reimplemented from formatron.extractor.Extractor.

Definition at line 36 of file regex.py.

◆ kbnf_definition()

str formatron.formats.regex.RegexExtractor.kbnf_definition ( self)

Reimplemented from formatron.extractor.Extractor.

Definition at line 50 of file regex.py.

Member Data Documentation

◆ _regex

formatron.formats.regex.RegexExtractor._regex
protected

Definition at line 25 of file regex.py.


The documentation for this class was generated from the following file: