Redundant character escape '\/' in RegExp

created at 03-20-2021 views: 55


if you got this warning, it means you used too many \ symbols, the  / characters in the regular expression do not need to be escaped with \/.


I got this problem in my Pycharm IDE when I was learning Ryan Mithcell's book about web scratching, at where we try to match some pictures in a web page, we would use:

imges = bs.findAll('img', {'src':re.compile('\.\.\/img\/gifts\/img.*\.jpg')})

however, there is no need to escape these \s here:

imges = bs.findAll('img', {'src':re.compile('\.\./img/gifts/img.*\.jpg')})

Anyway, both worked well if you test them, except you don't want to get reminders from Pycharm or any other IDEs, the second one would be suitable and shorter for you.

created at:03-20-2021
edited at: 03-21-2021: