字符串中的字符之间的字符串进行正则表达式匹配 [英] REGEX match from string between characters in string

查看:70
本文介绍了字符串中的字符之间的字符串进行正则表达式匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想在||之间匹配一个字符串在字符串中.
这是代码的拍子

match => ipi | IPI00831484 | IPI00832484.1未表征等"
字符串匹配= stream.Readline();

我想在||之间进行匹配例如IPI00831484


match = Regex.Match(match,"IPI00831484");

这行不通.谁能指导我了解磨损或其他替代解决方案?
谢谢,
Shekee

Hi,
I would like to match a string between || in a string.
Here is pat of the code

match = ">ipi|IPI00831484| IPI00832484.1 Uncharacterized etc"
string match = stream.Readline();

I would like to match the between the || e.g. the IPI00831484
with

match = Regex.Match(match, "IPI00831484");

This doesn''t work. Can anyone direct me to what is worng or any alternative solution?
Thanks,
Shekee

推荐答案

此处不需要正则表达式.使用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


这篇关于字符串中的字符之间的字符串进行正则表达式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆