我试图使用function (用于VSCode语法突出显示)将单词::捕获为两个不同的组,具体取决于::是否是前面的字符。据我所知,Oniguruma不支持条件词,因此我认为如果字符不存在,我可以将regex结果捕获到第1组,如果字符不存在,则将其捕获到第2组。
目前,我有以下几点:
(?>::\s*\b(function)\b)|\b(function)\b对代码进行测试的一些文本:
integer function fun_with_func_space( function )
integer, intent(inout) :: function
end function fun_with_func_space预期正则匹配
给定上面的文本,组$1应该
finds 1st and 2nd "function" in 'integer function fun_with_func_space( function )'
finds no match in 'integer, intent(inout) :: function'
finds "function" in 'end function fun_with_func_space'另一方面,组$2应
finds no match in 'integer function fun_with_func_space( function )'
find "function" in 'integer function fun_with_func_space( function )'
finds no match in 'end function fun_with_func_space'据我所知,下面的意思应该是:“捕获并退出到第2组,如果前面是::function,则在第1组中捕获function。”根据regex101.com,它应该可以工作:https://regex101.com/r/VtgeTD/1,但是我的语法高亮显示仍然失败。我做错了什么吗?
https://stackoverflow.com/questions/69518167
复制相似问题