Can I retain sanity to WebMatrix's Intellisense when using regular expressions in JavaScript?

旧时模样 提交于 2019-12-11 13:15:51

问题


I'm not sure why Microsoft hasn't allowed an Intellisense-friendly environment for using native regex with JavaScript in WebMatrix, but here is what I see when I attempt an otherwise normal JavaScript function:

As you can see, while this is perfectly valid JavaScript (using native regex), WebMatrix's Intellisense for my .js file is showing more random colors than a kaleidoscope.

I probably shouldn't be complaining, since it works, but I would like to restore human-readability if I can. I have noticed that this hasn't been mentioned anywhere else before (that I can find), and I was wondering if there were a more aesthetically pleasing way to handle this, given the environment.

I've tried using something like new RegEx(/&/g) for the first argument in the replace function, but of course, it produces the same glitch.

I've also tried storing the regex in a string, but I don't think that is in the format the first argument expects, so no dice there either.

I am not a master at regular expressions, by any means, so I apologize if I am overlooking a simple workaround here.

Is there anything I can do to retain this function in a more human-readable way?

--------------------------UPDATE-----------------------------

I just noticed that the line input = input.replace(/'/g, "&#x2C") is actually replacing an apostrophe with a comma. Rather than reload the picture, I will just mention that here (the proper hex code for apostrophe should be &#x27).


回答1:


new RegExp(/&/g) does not really make sense as the /&/g already creates a RegExp object. You can use new RegExp('&', 'g') instead.

By the way, this is not the only problem there is with JavaScript Intellisense.



来源:https://stackoverflow.com/questions/15251311/can-i-retain-sanity-to-webmatrixs-intellisense-when-using-regular-expressions-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!