Redundant character escape '\/' in RegExp

created at March 20, 2021, 10 a.m.


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.

Please log in to leave a comment.