我试图修改sublime中现有的语言定义
适用于SQL
目前(\@|@@)(\w)*
用于匹配本地声明的参数(例如@MyParam
)以及系统参数(例如@@Identity
或@@FETCH_STATUS
)
我试图将这些分成两组
系统参数我可以得到(\@\@)(\w)*
,但我的本地参数有问题。
(\@)(\w)*
匹配@MyParam和@@ Identity (^\@)(\w)*
仅突出显示第一场比赛(即@MyParam但不是@ MyParam2 有人可以帮助我使用正确的正则表达式吗?
答案 0 :(得分:1)
尝试使用以下正则表达式将本地参数和系统参数捕获到两个单独的组中。
(?<=^| )(@\w*)(?= |$)|(?<=^| )(@@\w*)(?= |$)
<强>更新强>
Sublime text 2支持\K
(丢弃之前的匹配),
(?m)(?:^| )\K(@\w*)(?= |$)|(?:^| )\K(@@\w*)(?= |$)
(?m) set flags for this block (with ^ and $
matching start and end of line) (case-
sensitive) (with . not matching \n)
(matching whitespace and # normally)
(?: group, but do not capture:
^ the beginning of a "line"
| OR
' '
) end of grouping
\K '\K' (resets the starting point of the
reported match)
( group and capture to \1:
@ '@'
\w* word characters (a-z, A-Z, 0-9, _) (0 or
more times)
) end of \1
(?= look ahead to see if there is:
' '
| OR
$ before an optional \n, and the end of a
"line"
) end of look-ahead
| OR
(?: group, but do not capture:
^ the beginning of a "line"
| OR
' '
) end of grouping
\K '\K' (resets the starting point of the
reported match)
( group and capture to \2:
@@ '@@'
\w* word characters (a-z, A-Z, 0-9, _) (0 or
more times)
) end of \2
(?= look ahead to see if there is:
' '
| OR
$ before an optional \n, and the end of a
"line"