I noticed that when I run a RegEx expression, it has inconsistent index positions of results when run in another machine. Am I missing something here...
Give this sql statement:
var sqlStatementRaw = $@"
--GO inline comment
CREATE PROC table1
AS
SELECT 1;
GO
/*
GO in inline comment block
*/
CREATE PROC table2
AS
SELECT 1;
GO
/* multiline comment block
GO
*/
CREATE PROC table3
AS
SELECT 1;
";
And this pieace of code:
var resultList = new List<CommentAnalyzerResult>();
//all comments
//https://stackoverflow.com/questions/7690380/regular-expression-to-match-all-comments-in-a-t-sql-script/33947706#33947706
var regex = new Regex(@"/\*(?>(?:(?!\*/|/\*).)*)(?>(?:/\*(?>(?:(?!\*/|/\*).)*)\*/(?>(?:(?!\*/|/\*).)*))*).*?\*/|--.*?\r?[\n]", RegexOptions.Singleline | RegexOptions.CultureInvariant);
var match = regex.Match(sqlStatementRaw);
while (match.Success)
{
var commentBlock = new CommentAnalyzerResult { Text = match.Value, Start = match.Index, End = match.Index + match.Length };
resultList.Add(commentBlock);
match = match.NextMatch();
}
Machine 1 results:
## results from my win10/x64 machine
Environment.OSVersion.Platform: Win32NT, Microsoft Windows NT 10.0.18362.0
Environment.NewLine.byteCount: 2
sqlStatementRaw.byteCount: 251
commentText.byteCount: 21
startPosition: 2, stopPosition: 23
commentText.byteCount: 34
startPosition: 75, stopPosition: 109
commentText.byteCount: 34
startPosition: 165, stopPosition: 199
Machine 2 results:
## results in AppVeyor Agents - Previous Visual Studio 2019 Image
Environment.OSVersion.Platform: Win32NT, Microsoft Windows NT 10.0.17763.0
Environment.NewLine.byteCount: 2
sqlStatementRaw.byteCount: 228
commentText.byteCount: 20
startPosition: 1, stopPosition: 21
commentText.byteCount: 32
startPosition: 68, stopPosition: 100
commentText.byteCount: 32
startPosition: 149, stopPosition: 181
EDIT:
- One machine is my Windows 10 dev machine and other is AppVeyor Build Image with VS2019
- Using .NET Core 3.0, both machines are 64-bit. The tests are run via MsTest drivers.
EDIT:
- Added more debug info: OS info, byte count