What regular expression variant is used in Visual

2019-05-10 01:08发布

问题:

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 \.