Regex to match word beginning with @
.net, c#, regex, vb.net
Solution
Use `\B@\w+` (non-word boundary).
For example:
string pattern = @"\B@\w+";
foreach (var match in Regex.Matches(@"@help me@ ple@se @now", pattern))
Console.WriteLine(match);
output:
@help
@now
BTW, you don't need to escape `@`.
http://ideone.com/nsT015
Problem
I am trying to develop some regex to find all words that start with an @: I thought that `\@\w+` would do it but this also matches words that have @ contained within them e.g. `@help me@ ple@se @now` matches at `Index: 0 Length 5, Index: 13 Length 3, Index: 17 Length 4` This shouldn't match at Index 13 should it?