正则表达式匹配多个名称,避免单个名称 [英] Regex to match multiple name and avoid single name

查看:118
本文介绍了正则表达式匹配多个名称,避免单个名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有案子。我想从输入中选择多个乘客姓名。如果输入只包含单个乘客名称,那么请避免输入字符串。



我创建了正则表达式,其中输入的多个名称可以正常工作但是它'当我想在输入中避免单个乘客姓名时,这不起作用。



我的目的是只选择那些包含多个乘客姓名但不是单个乘客的情况名字。



例如:这是输入字符串,其中在一个字符串中我有单个pax而在另一个字符串中我有多个pax我想要的是创建一个与多个pax匹配的正则表达式。



I have case. I want to select multiple passenger names from the input. if input contains only single passenger name then avoid that input string.

I have create regular expression in which It''s work for multiple names from the input but it''s not work, when I want to avoid single passenger name in the input.

My aim is to select only those case who contain multiple passenger names not the single passenger name.

for example: This is the input string where in one string i have single pax and in other i have more than one pax what i want is to create a regex which match with more than one pax.

string ymt4 = @"RP/NYC1S21DD/NYC1S21DD            WS/SU   6MAY13/0509Z   Y39ZRG                
NYC1S21DD/80948W/6MAY13                                                        
  1.CORTES RIVERA/MARIA(ADT)  ";// only one pax
 
string ymt5 = @"RT29PVZU
--- TST RLR MSC ---                                                            
RP/NYC1S21DD/NYC1S21DD            WS/SU   6MAY13/0452Z   29PVZU                
NYC1S21DD/9999WS/6MAY13                                                        
  1.ALVARADO/RITA(ADT)   2.CABELLO/LUIS CARLOS(ADT)                            
  3.CABELLO/CINDY(ADT)   4.GUTIERREZ/MARTHA HILDA(ADT) ";//more than one pax





我使用的正则表达是\\\\。[a-zA-Z] \S(。+)



这个正则表达式的主要问题是匹配单个和多个pax,因为我只想匹配单个pax。这就是为什么我要你帮助的人



提前谢谢



Regex i used for it is \d\.[a-zA-Z]\S(.+)

The main problem with this regex is that is match single as well as multiple pax where as i only want to match single pax. That''s why i want you help guys

Thanks in advance

推荐答案

试试这个正则表达式@ [0-9] * \。[A-Za-z] *

示例

try this regex @"[0-9]*\.[A-Za-z]*"
example
string ymt4 = @"RP/NYC1S21DD/NYC1S21DD            WS/SU   6MAY13/0509Z   Y39ZRG                
NYC1S21DD/80948W/6MAY13                                                        
  1.CORTES RIVERA/MARIA(ADT)  ";// only one pax
 
string ymt5 = @"RT29PVZU
--- TST RLR MSC ---                                                            
RP/NYC1S21DD/NYC1S21DD            WS/SU   6MAY13/0452Z   29PVZU                
NYC1S21DD/9999WS/6MAY13                                                        
  1.ALVARADO/RITA(ADT)   2.CABELLO/LUIS CARLOS(ADT)                            
  3.CABELLO/CINDY(ADT)   4.GUTIERREZ/MARTHA HILDA(ADT) ";//more than one pax
MatchCollection matches = Regex.Matches(ymt4 , @"[0-9]*\.[A-Za-z]*");
if(matches.Count>1)
     MessageBox.Show(matches.Count.ToString());


我用这个正则表达式(2 \。[Az] \S(。+))它将获取多个pax并避免单个pax
i use this regex (2\.[A-z]\S(.+)) it will fetch multiple pax and avoid single pax


这篇关于正则表达式匹配多个名称,避免单个名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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