class_docstr: A component to parse the output of a Generator to `Answer` objects using regular expressions.
docstr: :param pattern: The regular expression pattern to use to extract the answer text from the generator output.
                  If not specified, the whole string is used as the answer. The regular expression can have at
                  most one capture group. If a capture group is present, the text matched by the capture group
                  is used as the answer. If no capture group is present, the whole match is used as the answer.
                  Examples:
                      `[^\n]+$` finds "this is an answer" in a string "this is an argument.\nthis is an answer".
                      `Answer: (.*)` finds "this is an answer" in a string "this is an argument. Answer: this is an answer".
                  Default: `None`.
  :param reference_pattern: The regular expression pattern to use for parsing the document references.
                            We assume that references are specified as indices of the input documents and that
                            indices start at 1.
                            Example: `\[(\d+)\]` finds "1" in a string "this is an answer[1]".
                            If not specified, no parsing is done, and all documents are referenced.
                            Default: `None`.
docstr_tok: [":","param","pattern",":","The","regular","expression","pattern","to","use","to","extract","the","answer","text","from","the","generator","output",".","If","not","specified",",","the","whole","string","is","used","as","the","answer",".","The","regular","expression","can","have","at","most","one","capture","group",".","If","a","capture","group","is","present",",","the","text","matched","by","the","capture","group","is","used","as","the","answer",".","If","no","capture","group","is","present",",","the","whole","match","is","used","as","the","answer",".","Examples",":","`","[","^\\n","]","+","$","`","finds","``","this","is","an","answer","''","in","a","string","``","this","is","an","argument.\\nthis","is","an","answer","''",".","`","Answer",":","(",".","*",")","`","finds","``","this","is","an","answer","''","in","a","string","``","this","is","an","argument",".","Answer",":","this","is","an","answer","''",".","Default",":","`","None","`",".",":","param","reference_pattern",":","The","regular","expression","pattern","to","use","for","parsing","the","document","references",".","We","assume","that","references","are","specified","as","indices","of","the","input","documents","and","that","indices","start","at","1",".","Example",":","`","\\","[","(","\\d+",")","\\","]","`","finds","``","1","''","in","a","string","``","this","is","an","answer","[","1","]","''",".","If","not","specified",",","no","parsing","is","done",",","and","all","documents","are","referenced",".","Default",":","`","None","`","."]
code: def __init__(
      self,
      pattern: Optional[str] = None,
      reference_pattern: Optional[str] = None,
  ):
      """
      :param pattern: The regular expression pattern to use to extract the answer text from the generator output.
                      If not specified, the whole string is used as the answer. The regular expression can have at
                      most one capture group. If a capture group is present, the text matched by the capture group
                      is used as the answer. If no capture group is present, the whole match is used as the answer.
                      Examples:
                          `[^\\n]+$` finds "this is an answer" in a string "this is an argument.\\nthis is an answer".
                          `Answer: (.*)` finds "this is an answer" in a string "this is an argument. Answer: this is an answer".
                      Default: `None`.
      :param reference_pattern: The regular expression pattern to use for parsing the document references.
                                We assume that references are specified as indices of the input documents and that
                                indices start at 1.
                                Example: `\\[(\\d+)\\]` finds "1" in a string "this is an answer[1]".
                                If not specified, no parsing is done, and all documents are referenced.
                                Default: `None`.
      """
      if pattern:
          AnswerBuilder._check_num_groups_in_regex(pattern)
  
      self.pattern = pattern
      self.reference_pattern = reference_pattern
  
file_path: haystack/haystack/components/builders/answer_builder.py
imports: import logging
  import re
  from typing import List, Dict, Any, Optional
  from haystack import component, GeneratedAnswer, Document
label_desc: Use image node_id 1 to create a new AnswerBuilder object  with example: obj = AnswerBuilder(pattern, reference_pattern)