Searches for a pattern in the text.

    .. code-block:: jinja

        {% set my_text = 'abcd' %}
        {{ my_text | regex_search('^(.*)BC(.*)$', ignorecase=True) }}

    will be rendered as:

    .. code-block:: text

        ('a', 'd')
19279
def regex_search(txt, rgx, ignorecase=False, multiline=False):
    '''
    
    '''
    flag = 0
    if ignorecase:
        flag |= re.I
    if multiline:
        flag |= re.M
    obj = re.search(rgx, txt, flag)
    if not obj:
        return
    return obj.groups()
595662
def grep(pattern, &block)
      result = select { |item| pattern === item }
      result = result.map(&block) if block_given?
      return result
    end
669749
def pattern(self):
        
        if self.dynamic_version_of is not None:
            return self.dynamic_version_of.pattern

        if not self._pattern:
            self._pattern = re.compile('^%s_(.+)$' % self.name)
        return self._pattern
1308431
def beta_code(self, text):
        
        text = text.upper().replace('-', '')
        for (pattern, repl) in self.pattern1:
            text = pattern.subn(repl, text)[0]
        for (pattern, repl) in self.pattern2:
            text = pattern.subn(repl, text)[0]
        # remove third run, if punct list not used
        for (pattern, repl) in self.pattern3:
            text = pattern.subn(repl, text)[0]
        return text
190149
def compile_header_pattern(comments)
        re = comments.map { |c|
          case c
          when String
            "(?:#{Regexp.escape(c)}.*\\n?)+"
          when Array
            "(?:#{Regexp.escape(c[0])}(?m:.*?)#{Regexp.escape(c[1])})"
          else
            raise TypeError, "unknown comment type: #{c.class}"
          end
        }.join("|")
        Regexp.compile("\\A(?:(?m:\\s*)(?:#{re}))+")
      end
431872
def code_block(self, code, language, indent=0):
        
        if language not in [None, "console", "python", "ruby", "c"]:
            raise
        prefix = "\t" * indent
        code_prefix = "\t" * (indent + 1)
        lines = list()
        lines.append(prefix + ".. code-block:: %s" % language)
        lines.append(prefix)
        for line in code.split("\n"):
            lines.append(code_prefix + line.strip())
        return "\n".join(lines)
1326535
def verify_pattern(pattern):
    

    regex = re.compile("^!?[a-zA-Z]+$|[*]{1,2}$")

    def __verify_pattern__(__pattern__):
        if not __pattern__:
            return False
        elif __pattern__[0] == "!":
            return __verify_pattern__(__pattern__[1:])
        elif __pattern__[0] == "[" and __pattern__[-1] == "]":
            return all(__verify_pattern__(p) for p in __pattern__[1:-1].split(","))
        else:
            return regex.match(__pattern__)
    return all(__verify_pattern__(p) for p in pattern.split("/"))
284725
def content_match?(content)
      if pattern.is_a?(String)
        content.any? { |thing| thing == pattern }
      else
        content.any? { |thing| thing =~ pattern }
      end
    end
134299
def analyse_text(text):
        
        if re.match(r'^\s*REBOL\s*\[', text, re.IGNORECASE):
            # The code starts with REBOL header
            return 1.0
        elif re.search(r'\s*REBOL\s*[', text, re.IGNORECASE):
            # The code contains REBOL header but also some text before it
            return 0.5
31298
def pre_process_code_block(block):
        
        if 'indent' in block and block['indent']:
            indent = r'^' + block['indent']
            block['content'] = re.sub(indent, '', block['icontent'],
                                      flags=re.MULTILINE)
499737
def grep_v(pattern, &block)
      result = select { |item| !(pattern === item) }
      result = result.map(&block) if block_given?
      return result
    end
93792
def _regexp(expr, item):
    ''' 
    '''
    reg = re.compile(expr)
    return reg.search(item) is not None
933311
def run(self, lines):
        
        text = "\n".join(lines)
        while 1:
            m = FENCED_BLOCK_RE.search(text)
            if not m:
                break
            lang = m.group('lang')
            linenums = bool(m.group('linenums'))
            html = highlight_syntax(m.group('code'), lang, linenums=linenums)
            placeholder = self.markdown.htmlStash.store(html, safe=True)
            text = '{}\n{}\n{}'.format(
                text[:m.start()],
                placeholder,
                text[m.end():]
            )

        return text.split("\n")
816045
def _matches_patterns(self, matches, context):
        
        if not self.disabled(context):
            patterns = self.effective_patterns(context)
            for pattern in patterns:
                if not pattern.disabled(context):
                    pattern_matches = pattern.matches(matches.input_string, context)
                    if pattern_matches:
                        log(pattern.log_level, "Pattern has %s match(es). (%s)", len(pattern_matches), pattern)
                    else:
                        pass
                        # log(pattern.log_level, "Pattern doesn't match. (%s)" % (pattern,))
                    for match in pattern_matches:
                        if match.marker:
                            log(pattern.log_level, "Marker found. (%s)", match)
                            matches.markers.append(match)
                        else:
                            log(pattern.log_level, "Match found. (%s)", match)
                            matches.append(match)
                else:
                    log(pattern.log_level, "Pattern is disabled. (%s)", pattern)
950028
def pattern_to_regex(pattern: str) -> str:
    
    if pattern and pattern[-1] == "*":
        pattern = pattern[:-1]
        end = ""
    else:
        end = "$"
    for metac in META_CHARS:
        pattern = pattern.replace(metac, "\\" + metac)

    return "^" + VARS_PT.sub(regex_replacer, pattern) + end
84937
def code_block(self, node, entering):
        ''''''
        if self.use_pygments:
            self.cr()
            info_words = node.info.split() if node.info else []

            if len(info_words) > 0 and len(info_words[0]) > 0:
                try:
                    lexer = get_lexer_by_name(info_words[0])
                except ValueError:
                    # no lexer found - use the text one instead of an exception
                    lexer = TextLexer()
            else:
                lexer = TextLexer()

            formatter = HtmlFormatter(**self.pygments_options)
            parsed = highlight(node.literal, lexer, formatter)
            self.lit(parsed)
            self.cr()
        else:
            super().code_block(node, entering)
723362
def compile_pattern(word):
    
    return re.compile(r'^%s$' % re.sub(r'\?', '[a-z]',
                                       dicts.sanitize_word(word)))