def _escape_for_regex(text):
    """Escape ``text`` to allow literal matching using egrep"""
    re_specials = '\\^$|(){}[]*+?.'
    sh_specials = '\\$`"'
    re_chars = []
    sh_chars = []
    for c in text:
        if c == '\n':
            continue
        if c in re_specials:
            re_chars.append('\\')
        re_chars.append(c)
    for c in re_chars:
        if c in sh_specials:
            sh_chars.append('\\')
        sh_chars.append(c)
    return ''.join(sh_chars)
