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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With