I am working on a web site with several other developers and we have had problems where people commit JavaScript code with AJAX calls that use URL's relative to the site root. An example would be /Home/Index which will not work if the site is hosted in a vir开发者_Go百科tual directory.
To get round the problem we use a $.url() method to convert it to a full path, e.g.
$("#container").load($.url("/Home/Index"))
I am trying to write a unit test that will search each JavaScript file and find places where the $.url method is not being used. The only problem is that I cannot seem to write a regex expression to do this. I have tried the following:
(?!\$\.url\()"(/\w*)+"
But this does not work. I cannot find a way to say that I don't want the $.url in front. Does anyone know if this is possible? Note that I need regular expressions that are compatible with .NET
Thanks.
You just need to change your lookahead to a lookbehind:
(?<!\$\.url\()"(/\w*)+"
Why don't you just search for something like this?
\.load\("(/\w*)+"\)
Or something escapes me?
精彩评论