I’m trying to parse a fragment of a stacktrace, which looks pretty much like this:
at Test.Test1() in C:\Projects\Project\Test.cs:line 37
Using a regex like this works as intended:
at (.*?) in (.*?):line (\d*)
This matches
- Test.Test1()
- C:\Projects\Project\Test.cs
- 37
This regex is hardcoded to an english stacktrace, so there are obviously no matches if the stacktrace is in another language, such as swedish:
vid Test.Test1() i C:\Projects\Project\Test.cs:rad 37
To make the matching more language neutral I tried this regex out:
(.*?) .*? (.*?) (\d*)
This matches
- Test.Test1()
- C:\Projects\Project\Test.cs:line
- 37
The question is how would I match the file path without the trailing :line?
You could try hard-coding the necessity of having a colon at the second place in the file name part:
After the colon following the drive letter there obviously can’t be any further colon that would be part of the file name. You might have to cope with UNC paths, though, so the following might fix that:
which makes the colon optional to allow for UNC paths.
So, your captures for the file name part with the “:line” following might look like this: