正则表达式匹配字符串 [英] Regex to match string
问题描述
大家好,
请帮我找到正则表达式:
我的价值如下:''Martin Lucas''
和我的输入字符串是:''我的名字是Martin Lucas,我和ABC先生一起工作'。
现在我必须匹配是否名称''Martin Lucas''存在于给定的字符串中。
请建议正则表达式
之前我正在使用
@(^ | \ s)+ mentioned_profilename + @(\ s | $)
这是我的正则表达式..它工作正常。但不能匹配值以''结束',''
例如,如果以下是我的字符串
你好@Nagsdada KumarDada,@ Vishal Shimpi和@Hatim Jawad
这个@Nagsdada KumarDada没有得到匹配
)
这在我的正则表达式中...它工作正常。但不能匹配值以''结束,''
例如,如果以下是我的字符串
你好@Nagsdada KumarDada,@ Vishal Shimpi和@Hatim Jawad
@Nagsdada KumarDada没有得到匹配
一个正则表达式可能是矫枉过正:string.Contains方法也会这样做。
但正则表达式非常非常简单:
Martin Lucas
或可能
Martin \ + + Lucas
但是为了真正的准确性:
(?< = \\\ )Martin\s +卢卡斯(?= [\s。?')!])
Hi all,
Please help me to find regex:
I have value like: ''Martin Lucas''
and my input string is : ''My name is Martin Lucas, i am working with Mr ABC''.
now i have to match whether the name ''Martin Lucas'' is exist in given string.
please suggest the regular expression
previously i was using
@"(^|\s)" + mentioned_profilename + @"(\s|$)"
this in my regex.. it was working fine. but can not match the value ends with '',''
eg if following is my string
hello @Nagsdada KumarDada, @Vishal Shimpi and @Hatim Jawad
in this @Nagsdada KumarDada was not getting match
)"
this in my regex.. it was working fine. but can not match the value ends with '',''
eg if following is my string
hello @Nagsdada KumarDada, @Vishal Shimpi and @Hatim Jawad
in this @Nagsdada KumarDada was not getting match
A regex is probably overkill: the string.Contains method would do it as well.
But the regex is very, very simple:
Martin Lucas
or possibly
Martin\s+Lucas
But for real accuracy:
(?<=\s)Martin\s+Lucas(?=[\s,.?'")!])
这篇关于正则表达式匹配字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!