why does this python regex return no match?
Question: 
    >>> match = re.search(r'\d', 'ca\d')
    >>> type(match) 
    <type 'NoneType'>
    

From my understanding 'r' means don't do any special processing with
blackslashes and just return the raw string.

Also, why do i get the output below:

    
    
    >>> match = re.search(r'\a', 'ca\a')
    >>> match.group()
    '\x07'
    


Answer: Because your input string has no digit. `\d` means `capture a digit`.

If you want to capture a literal `\d`, you should use `\\d` pattern.

See [example here](https://regex101.com/r/aK4fA4/1).

This program

    
    
    import re
    p = re.compile(ur'\\d')
    test_str = u"ca\d"
    print re.search(p, test_str).group(0)
    

Will output `\d`.

As for `r''`, please check this [re
documentation](https://docs.python.org/2/library/re.html):

> The solution is to use Python’s raw string notation for regular expression
> patterns; backslashes are not handled in any special way in a string literal
> prefixed with 'r'. So r"\n" is a two-character string containing '\' and
> 'n', while "\n" is a one-character string containing a newline. Usually
> patterns will be expressed in Python code using this raw string notation.

It does not mean it does not process slashes anyhow, this just lets you use a
single slash instead of a doubled one. The slash is meaningful before `d` in a
regular expression.

And as for `\a`, there is no such a regex metacharacter, so `\` is treated as
a literal.

