I use Selenium, it costs phantomJS driver. The task is to disable css. The code is already there, but how to format it for Java is not clear to me.

jsDriver.executePhantomJS( "this.onResourceRequested = function(request, net) { " + "if ((/http:\/\/.+?\.css/gi).test(requestData['url']) || requestData['Content-Type'] == 'text/css') {" + "console.log('The url of the request is matching. Aborting: ' + requestData['url']);" + "request.abort();" + "}" + "};"); 

Swears at the line with the condition if ((/http:\/\/.+?\.css/gi).test(requestData['url']) || requestData['Content-Type'] == 'text/css') {

Illegal escape character in string literal

How to proceed? Wednesday Intellij

UPD: does not work like this:

 (/http:\\/\\/.+?\\.css/gi) 

    1 answer 1

    Because all these shieldings do not work. They are applied on the line itself with the code and inside is not what is needed. Actually, this is where the warning appears, since shielding intended for regular use is actually used in a line where slashes and dots are not required to be shielded.

    Well, of course, such a code will not work. To fix it, you need to escape backslashes yourself.

    • How exactly? Can you tell me? - jessez
    • @jessez, well \\ same ... - Qwertiy
    • How to escape characters, I know, but if I write this: ((/http:\\/\\/.+?\\.css/gi) : ((/http:\\/\\/.+?\\.css/gi) will it work? - jessez
    • @jessez 1. Yes, if there are no errors in the code. 2. And take and check? - Qwertiy
    • Checked does not work. - jessez