Reorder Regex Match Groups

若如初见. 提交于 2019-12-24 14:42:30

问题


I am writing a Sublime Text 2 build configuration for grails, which includes a regular expression (perl style) to parse error messages in to file, line, column, and message parts. The errors come from the grails CLI in the following format:

{Project_Directory}/SourceFile.groovy: 19: errror_message @ line 19, column 5.

My current regex matches all four parts, but Sublime seems to require that the matches occur in order, that is match group 1 = file name, 2 = line number, 3 = column number, 4 = errror message. Grails is reporting items 3 and 4 in reverse order, so I need to write a regex that will put the column number in match group 3 and the error message in group 4. My current regex (which matches, but doesn't reverse groups 3 and 4) is as follows:

^(.+?): (\d+): (.+?) \@ line \d+, column (\d+)\.$

Any ideas? Is this even possible? Does anybody know if sublime will accept named groups instead of numbered groups?


回答1:


^(.+?): (\d+): (?=.+? \@ line \d+, column (\d+)\.$)(.+?) \@

Better (less backtracking on failure):

^([^:]+): (\d+): (?=[^@]+ \@ line \d+, column (\d+)\.$)([^@]+) \@


来源:https://stackoverflow.com/questions/11230839/reorder-regex-match-groups

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!