Sublime Forum

How to replace dots (.) with slashes (/) when using `file_regex`?


I am implementing a goto file/function with file_regex on my Python Projects build systems. For example, when I am using the following build system:

			"path": ".",
            "name": "Run Project",
            "file_regex": "^\\d\\d:\\d\\d:\\d\\d:\\d\\d\\d.\\d\\d\\d\\d\\d\\d \\d.\\d\\de-\\d\\d - (\\w+(?:\\.\\w+(?!\\.\\w+:))*)[^:]+:(\\d+) - (.*)$",
            "shell": true,
            "env": {"PYTHONIOENCODING": "utf8"},
            "syntax": "Packages/Text/Plain text.tmLanguage",
            "working_dir": "$project_path/source",
            "shell_cmd": "python -v TestChomskyGrammar.test_grammarInvalidNonTerminalException -f",

And some python log mine on the output.exec build panel has:

23:32:13:530.091047 1.22e-04 - grammar.grammar.<module>:58 - Importing grammar.grammar
23:32:13:657.607079 1.54e-04 - source.<module>:60 - Importing __main__

And I double click on the first line, I got this on the Sublime Text console:

found result file, line, col of [grammar.grammar], [58], [Importing grammar.grammar] full path: /D/grammar.grammar
Unable to open /D/grammar.grammar

It is not interpreting the dot (.) as a file path separator. How can I intercept the file_regex results before Sublime Text tries to open the file and replace the dots (.) with slashes (/)? So /D/grammar.grammar becomes /D/grammar/grammar?

One way I can think of, is to implement my own system of file_regex, like my_file_regex and when I double click on the output build panel, I perform my custom go to file and open the file by myself, without relying on Sublime Text internals result_file_regex voodoo. (by creating a mouse bind I can detect a double click by timing the differences between the clicks, get the current line, apply my my_file_regex, extract the capturing groups and finally open the file replacing dots (.) with slashes (/))

Related threads:



Here is a solution:

For more related threads on this topic:



Try this,
Replace /'/'/g with /[/]/g

  • / - start of the regex
  • [/] match characters inside square brackets
  • /g end of the regex