Search code examples
regexbuildsystemsublimetext3capture

Capturing errors in sublime build file using regex in Sublime Text 3


I'm trying to capture the errors I get when coding in Sublime Text 3. The errors look like this:

filename.extension:lineNumber: error: "The error message"
            Code that = is.wrong();
                          ^  <--Arrow pointing to the error

My regex capturing code is

"result_file_regex": "^(...*?):([0-9]*): error: (.*)"

which according to this documentation should be correct, except there is no column number to capture.

Whenever I try to run a wrong code using this regex it errors to the sublime output

str expected, not dict

What am I doing wrong?


Solution

  • result_file_regex A Perl-style regular expression to capture up to four fields of error information from a results view, namely: filename, line number, column number and error message. Use groups in the pattern to capture this information. The filename field and the line number field are required.

    http://docs.sublimetext.info/en/latest/reference/build_systems/configuration.html?highlight=result_file_regex

    It says "result_file_regex" in the docs, but that's wrong, the key for builds "file_regex".

    How do we match something like:

    filename.extension:lineNumber: error: "The error message"
    

    Let's start with the simplest match, the filename and the line number:

    "file_regex": "^([^:]+):([0-9]+):.*$"
    

    The above matches the filename and the line number (two matches).

    "file_regex": "^([^:]+):([0-9]+):([0-9]+)?.*$"
    

    The above matches the filename, line number and an optional column number.

    "file_regex": "^([^:]+):([0-9]+):([0-9]+)? error: (.+)$"
    

    The above matches all four elements: the filename, line number, column number (optional), and the error message.