Reputation: 1571
For a custom syntax highlighting in "Sublime Text 2" I need a solution to regex the devisor "/" but not the double-slash comment "//"
example code for regex matching could look like this:
void main()
{
int a = 10/2; // simple devision
// ^ ^
// | +-- comment (the regex below will match the second slash)
// +-- devisor
}
my current regex looks like:
\/(?!\/)
The result of this regex matches also the second slash in the comment. How could I define a regex that only matches the devisor but does not touch the double slash comment at all?
Upvotes: 0
Views: 41
Reputation: 869
Use a non-matching character class:
[^\/]*(\/)[^\/]*
This will match any /
that is not preceded or followed by another /
.
Upvotes: 0
Reputation: 1904
You were close. You specified a negative-lookahead assertion that a slash cannot follow a slash. And now you also need to specify a negative-lookbehind assertion that a slash cannot precede a slash.
(?<!\/)\/(?!\/)
Upvotes: 1