What regular expression variant is used in Visual Studio code?

ⅰ亾dé卋堺 提交于 2019-12-10 10:19:23

问题


I know that I can use Ruby's regular expressions in a tmLanguage file, however that seems not to be the case in other configuration files, e.g. for extensions. Take for example the firstLine value in the language contribution. I get errors when I use character classes (e.g. \s or \p{L}). Hence I wonder what is actually allowed there. How would you match whitespaces there?

Update: After the comments I tried this:

"firstLine": "^(lexer|parser)?\\s*grammar\\w+;"

which is supposed to match a first line like lexer grammar G1; or just grammar G1;. Is there a way to test if that RE works, because I have no validation otherwise?

Update 2:

It's essential to use the correct grammar and it will magically work:

"firstLine": "^(lexer|parser)?\\s*grammar\\s*\\w+\\s*;"

回答1:


.NET regular expressions use a syntax that is largely based on Perl 5, however it does add a few new features such as named capture groups and right to left matching, so the two should not be thought of as identical. Here is the full MSDN documentation for .NET regular expressions:

.NET Framework Regular Expressions

\s is a valid character class in .NET, but it is difficult to say exactly what the problem is without seeing the code you are trying. Andrew could be right, that you just did not escape the \.



来源:https://stackoverflow.com/questions/39065478/what-regular-expression-variant-is-used-in-visual-studio-code

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