且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

字符串中的字符之间的字符串进行正则表达式匹配

更新时间:2023-02-17 23:05:34

此处不需要正则表达式.使用String.Split:

No need for a Regular Expression here. Use String.Split:

String match = ">ipi|IPI00831484| IPI00832484.1 Uncharacterized etc"
String[] values = match.Split(new char[] {''|''});
//values now contains three string 
String yours = values[1]; 



干杯!



Cheers!


如果您更喜欢正则表达式,请尝试以下操作:

If you prefer regular expressions then try this:

Regex rx = new RegEx("|[^|]*|");
Match match = rx.Match(">ipi|IPI00831484| IPI00832484.1 Uncharacterized etc");
if(match.Succeess)
{
    Console.WriteLine(match.Value);
}



干杯!



Cheers!


您尝试过的正则表达式示例表明,您甚至没有尝试阅读有关如何使用常规异常的信息.为什么要进行猜测工作?

您在CodeProject上提问的想法也不是很合理.您问一两次,现在问什么.这就像询问"2 * 2多少钱",然后问"11 * 3多少钱?",您不是这样认为的.同时,还有更多的文献和参考文献(您可能无法记住所有内容,需要参考文献).

阅读此内容: http://en.wikipedia.org/wiki/Regex [ http://msdn.microsoft.com/en-us/library/hs600312.aspx [ http://cstheory.stackexchange.com/questions/1854/is-finding-the-minimum-regular-expression-an-np-complete-problem [ ^ ],以供参考: http://www.regular-expressions.info/reference.html [ http://www.regular-expressions.info/refadv.html [ ^ ].

祝你好运,
—SA
Your attempted Regex sample shows that you did not even try to read on how to use Regular Exception. Why doing guess work?

Your idea of asking your question on CodeProject was not so reasonable either. You ask one, two time, now what. This is pretty much like asking "How much is 2*2", and later "How much is 11*3?", don''t you think so. At the same time there is more then enough literature and references (you cannot remember it all, will need a reference).

Read this: http://en.wikipedia.org/wiki/Regex[^], http://msdn.microsoft.com/en-us/library/hs600312.aspx[^], use http://cstheory.stackexchange.com/questions/1854/is-finding-the-minimum-regular-expression-an-np-complete-problem[^], for reference: http://www.regular-expressions.info/reference.html[^] and http://www.regular-expressions.info/refadv.html[^].

Good luck,
—SA