Wrap hashtagged from string using regex

Well, as the title says ... I want to capture a specific word that hashtagged in a string.

Example: This is a line in which # contains hashtags!

I want to highlight the word contains from a string as a new line.

I can imagine that this is a very simple problem, but I really can't get it to work.

+6
source share
2 answers

How good is this template? Theoretically true:

"(?<=#)\w+" 

will do it.

Edit, for greater completeness, answer:

 string text = "This is a string that #contains a hashtag!"; var regex = new Regex(@"(?<=#)\w+"); var matches = regex.Matches(text); foreach(Match m in matches) { Console.WriteLine(m.Value); } 
+11
source
 string input = "this is a string that #contains a hashtag!"; var tags = Regex.Matches(input, @"#(\w+)").Cast<Match>() .Select(m => m.Groups[1].Value) .ToList(); 
+3
source

All Articles