正则表达式来查找与一个特定的字符开头的单词 [英] Regex to find words that start with a specific character
本文介绍了正则表达式来查找与一个特定的字符开头的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想找到的话像一个特定的字符开头:
I am trying to find words starts with a specific character like:
Lorem存有#text二Lorem存有。
你好吗。没关系。完成。
现在的东西#else伪指令。
Lorem ipsum #text Second lorem ipsum. How #are You. It's ok. Done. Something #else now.
我需要得到所有单词以#开头。所以我的预期结果是#text,#are,#else伪
I need to get all words starts with "#". so my expected results are #text, #are, #else
任何想法?
推荐答案
搜索:
- 未尝不是一个单词字符然后
- #
- 某些文字字符
所以,试试这个:
/(?<!\w)#\w+/
或者在C#中它是这样的:
Or in C# it would look like this:
string s = "Lorem ipsum #text Second lorem ipsum. How #are You. It's ok. Done. Something #else now.";
foreach (Match match in Regex.Matches(s, @"(?<!\w)#\w+"))
{
Console.WriteLine(match.Value);
}
输出:
#text
#are
#else
这篇关于正则表达式来查找与一个特定的字符开头的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文