code: def regex_strategy(
      regex,
      fullmatch,
      *,
      alphabet,
      _temp_jsonschema_hack_no_end_newline=False,
  ):
      if not hasattr(regex, "pattern"):
          regex = re.compile(regex)
  
      is_unicode = isinstance(regex.pattern, str)
  
      parsed = sre_parse.parse(regex.pattern, flags=regex.flags)
  
      if fullmatch:
          if not parsed:
              return st.just("" if is_unicode else b"")
          return base_regex_strategy(regex, parsed, alphabet).filter(
              regex.fullmatch
          )
  
      if not parsed:
          if is_unicode:
              return st.text(alphabet=alphabet)
          else:
              return st.binary()
  
      if is_unicode:
          base_padding_strategy = st.text(alphabet=alphabet)
          empty = st.just("")
          newline = st.just("\n")
      else:
          base_padding_strategy = st.binary()
          empty = st.just(b"")
          newline = st.just(b"\n")
  
      right_pad = base_padding_strategy
      left_pad = base_padding_strategy
  
      if parsed[-1][0] == sre.AT:
          if parsed[-1][1] == sre.AT_END_STRING:
              right_pad = empty
          elif parsed[-1][1] == sre.AT_END:
              if regex.flags & re.MULTILINE:
                  right_pad = st.one_of(
                      empty, st.builds(operator.add, newline, right_pad)
                  )
              else:
                  right_pad = st.one_of(empty, newline)
  
              # This will be removed when a regex-syntax-translation library exists.
              # It's a pretty nasty hack, but means that we can match the semantics
              # of JSONschema's compatible subset of ECMA regex, which is important
              # for hypothesis-jsonschema and Schemathesis. See e.g.
              # https://github.com/schemathesis/schemathesis/issues/1241
              if _temp_jsonschema_hack_no_end_newline:
                  right_pad = empty
  
      if parsed[0][0] == sre.AT:
          if parsed[0][1] == sre.AT_BEGINNING_STRING:
              left_pad = empty
          elif parsed[0][1] == sre.AT_BEGINNING:
              if regex.flags & re.MULTILINE:
                  left_pad = st.one_of(
                      empty, st.builds(operator.add, left_pad, newline)
                  )
              else:
                  left_pad = empty
  
      base = base_regex_strategy(regex, parsed, alphabet).filter(
          regex.search
      )
  
      return maybe_pad(regex, base, left_pad, right_pad)
  
imports: import operator
  import re
  from hypothesis.errors import InvalidArgument
  from hypothesis.internal import charmap
  from hypothesis.strategies._internal.lazy import unwrap_strategies
  from hypothesis.strategies._internal.strings import OneCharStringStrategy
  from hypothesis import reject, strategies
  from hypothesis.internal.charmap import as_general_categories, categories
  from hypothesis.internal.compat import add_note, int_to_byte
label_desc: Use image node_id 8 for calling a global function with example usage: regex_strategy(regex, fullmatch) and returns: maybe_pad, base_regex_strategy, st, st, st