Reputation: 11
I'm designing a text editor with vs 2013 express.I want to find words that starting with a colon (:). Currently i use a regex for it.But it's not perfect. This is my regex - ":\w+" It finds words,but quite not the way i want. My objective is to find words starting with a colon.(first character of the word is a colon ex- :Test ) But the words only at the start of a line.(not from the middle of a sentence) And it should exclude words starting with two colons (::Test) Hope you guys could help me..
Upvotes: 0
Views: 1144
Reputation: 415
Whether any colon come in between in the line. or else you can use below code.
^:[^:]+
Try this too.
Upvotes: 0
Reputation: 174776
Use ^
anchor to match the start of a line.
^:(?!:)\S+
:(?!:)
This negative lookahead asserts that the :
would be followed by any but not of a :
OR
^:\w+
This matches the :
and the following word characters only if it is at the start of a line.
Upvotes: 2