0

大家好,我必须创建一个函数,在该函数中我必须调用一个正则表达式,以便在调用该正则表达式时它匹配一个字符串,但将其他字符串存储在数据表中,例如我有这样的字符串

string hello=@"RP/NYC1S21DD/NYC1S21DD            WS/SU   6MAY13/0509Z   **Y33ORG**                
NYC1S21DD/80948W/6MAY13                                                        
1.CORTES RIVERA/MARIA(ADT)   2.ROMERO VEGA/LISA(ADT)                         
3.SHIRA/MARK C(ADT)   4.SHIRA ROMERO/MARINA E(ADT)                           
5.SHIRA ROMERO/MONIQUE A(ADT)   6.SHIRA ROMERO/DYLAN M(CHD)                    
 )>SP1                                                                           
 RP/NYC1S21DD/NYC1S21DD            WS/SU   6MAY13/0509Z   XXXXXX                
 1.CORTES RIVERA/MARIA(ADT)                                                   
 2  UA1162 W 21JUN 5*BQNEWR HK1   150A 545A 21JUN  E  UA/GW176R               
 3  UA1209 W 21JUN 5*EWRLAX HK1   700A 955A 21JUN  E  UA/GW176R               

)>FXR                                                                              
 01 CORTES RI*/MARIA                                                            
 ITINERARY REBOOKED  /// when i found this line i want to fetch PNR number                                                      
 LAST TKT DTE 06MAY13 - SEE ADV PURCHASE";

在上面的字符串中,当我发现 ITINERARY REBOOKED 我想在 gridview 中显示 PNR 编号Y33ORG我该怎么做

4

1 回答 1

1

Use a look ahead assertion:

([*0-9A-Z]{10})(?=(.*ITINERARY.*REBOOKED.*?))

A PNR followed by "ITINERARY REBOOKED" text will match this with multiline regex flag ON.

1.. Matching when text present :

http://regexr.com?34pdm

2.. Not matching when text is not present :

http://regexr.com?34pds

于 2013-05-06T12:08:49.180 回答