I have tried this...
Dim myMatches As String() =
System.Text.RegularExpressions.Regex.Split(postRow.Item("Post"), "\b\#\b")
But it is splitting all words, I want an array of words that start with#
Thanks!
This seems to work...
c#
Regex MyRegex = new Regex("\\#\\w+");
MatchCollection ms = MyRegex.Matches(InputText);
or vb.net
Dim MyRegex as Regex = new Regex("\#\w+")
Dim ms as MatchCollection = MyRegex.Matches(InputText)
Given input text of...
"asdfas asdf #asdf asd fas df asd fas #df asd f asdf"
...this will yield....
"#asdf" and "#df"
I'll grant you that this does not get you a string Array but the MatchCollection is enumerable and so might be good enough.
Additionally, I'll add that I got this through the use of Expresso. which appears to be free. It was very helpful in producing the c# which I am very poor at. (Ie it did the escaping for me.) (If anyone thinks I should remove this pseudo-advert then please comment, but I thought it might be helpful :) Good times )
Since you want to include the words in the split you should use something like
"\b#\w+\b"
This includes the actual word there in the expression. However I'm not sure that's what you want. Could you provide an example of input and the desired output?
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