Python regex replacing \u2022

前端 未结 4 1204
死守一世寂寞
死守一世寂寞 2021-01-26 09:53

This is my string:

raw_list = u\'Software Engineer with a huge passion for new and innovative products. Experienced gained from working in both big and fast-grow         


        
4条回答
  •  攒了一身酷
    2021-01-26 10:24

    You're using a raw string, with the r. That tells Python to interpret the string literally, instead of actually taking escaped characters (such as \n).

    >>> r'\u2022'
    '\\u2022'
    

    You can see it's actually a double backslash. Instead you want to use >>> u'\u2022' and then it will work.

    Note that since you're doing a simple replacement you can just use the str.replace method:

    x = raw_list.replace(u'\u2022', ' ')
    

    You only need a regex replace for complicated pattern matching.

提交回复
热议问题