Reputation: 6170
I'm trying to modify an existing language definition in sublime
It's for SQL
Currently (\@|@@)(\w)*
is being used to match against local declared parameters (e.g. @MyParam
) and also system parameters (e.g. @@Identity
or @@FETCH_STATUS
)
I'm trying to split these into 2 groups
System parameters I can get like (\@\@)(\w)*
but I'm having problems with the local parameters.
(\@)(\w)*
matches both @MyParam and @@Identity(^\@)(\w)*
only highlights the first match (i.e. @MyParam but not @MyParam2Can someone help me with the correct regex?
Upvotes: 0
Views: 103
Reputation: 174726
Try the below regex to capture local parameters and system parameters into two separate groups.
(?<=^| )(@\w*)(?= |$)|(?<=^| )(@@\w*)(?= |$)
Update:
Sublime text 2 supports \K
(discards the previous matches),
(?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"
Upvotes: 1