class_docstr: A component to parse the output of a Generator to `Answer` objects using regular expressions.
docstr: Extract the answer string from the generator output using the specified pattern.
  If no pattern is specified, the whole string is used as the answer.
  
  :param replies: The output of the Generator. A string.
  :param pattern: The regular expression pattern to use to extract the answer text from the generator output.
docstr_tok: ["Extract","the","answer","string","from","the","generator","output","using","the","specified","pattern",".","If","no","pattern","is","specified",",","the","whole","string","is","used","as","the","answer",".",":","param","replies",":","The","output","of","the","Generator",".","A","string",".",":","param","pattern",":","The","regular","expression","pattern","to","use","to","extract","the","answer","text","from","the","generator","output","."]
code: def _extract_answer_string(
      reply: str, pattern: Optional[str] = None
  ) -> str:
      """
      Extract the answer string from the generator output using the specified pattern.
      If no pattern is specified, the whole string is used as the answer.
  
      :param replies: The output of the Generator. A string.
      :param pattern: The regular expression pattern to use to extract the answer text from the generator output.
      """
      if pattern is None:
          return reply
  
      if match := re.search(pattern, reply):
          # No capture group in pattern -> use the whole match as answer
          if not match.lastindex:
              return match.group(0)
          # One capture group in pattern -> use the capture group as answer
          return match.group(1)
      return ""
  
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 3 for calling the AnswerBuilder obj's underlying member method code with example usage: obj._extract_answer_string(reply, pattern) and returns: str, reply, match, match