首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

求正则表达式提取订单号跟商户订单号

2013-02-24 
求正则表达式提取订单号和商户订单号本帖最后由 yitogong 于 2013-01-31 21:23:16 编辑DIV idheaderDI

求正则表达式提取订单号和商户订单号
本帖最后由 yitogong 于 2013-01-31 21:23:16 编辑




<DIV id=header>
<DIV class=logo-contianer>
<H1 id=logo><A title="财付通 - 在线支付专家" href="https://www.tenpay.com/">财付通<SUB>腾讯旗下在线支付平台</SUB></A></H1>
<UL class=guide>
<LI><A href="https://www.tenpay.com/app/v1.0/switch_web.cgi?direct=v2&amp;target=https%3a%2f%2fwww.tenpay.com%2fapp%2fv1.0%2fcftaccount.cgi?ADTAG=TENPAY.PAY_CENTRE.DAOHANG.CFTACCOUNT" target=_blank>财付通首页</A> </LI>
<LI>|<A href="http://help.tenpay.com/" target=_blank>帮助</A> </LI>
<LI>|<A href="http://support.qq.com/cgi-bin/beta2/titlelist_simple?pn=0&amp;order=3&amp;fid=127" target=_blank>反馈</A> </LI>
<LI class=last-one>|<A href="https://www.tenpay.com/cgi-bin/v1.0/jump.cgi?u1=/zft/cs/cs.shtml?tid=1" target=_blank>申诉</A> </LI></UL>
<DIV class=action><SPAN style="DISPLAY: inline-block" id=guest-sign><SPAN id=snNoLog><A href="https://www.tenpay.com/zft/register_1.shtml">注册</A>|<A id=login href="#">登录</A></SPAN></SPAN><SPAN style="DISPLAY: none" id=snLog><SPAN id=head_true_name></SPAN><SPAN id=snCert></SPAN></SPAN><A class=recharge href="https://www.tenpay.com/v2/account/charge/net_bank.shtml?ADTAG=TENPAY_V2.CHARGE.HOME.LINK_NETBANK" target=_blank>充值</A> </DIV>
<DIV id=special-action class=action><SPAN><A href="https://www.tenpay.com/">返回财付通首页</A>|<A href="https://www.tenpay.com/">帮助中心</A></SPAN></DIV></DIV>
<DIV id=main-nav>
<UL>
<LI id=account_g><A href="https://www.tenpay.com/cgi-bin/v1.0/jump.cgi?u1=/cgi-bin/v1.0/check_balance.cgi">我的财付通</A> </LI>
<LI id=trade_g><A href="https://www.tenpay.com/cgi-bin/med/trans_manage.cgi">交易管理</A> </LI>
<LI id=favourable_g><A href="https://youhui.tenpay.com/cgi-bin/showinfo.cgi">优惠</A> </LI>
<LI id=gathering_g><A href="https://www.tenpay.com/cgi-bin/v1.0/jump.cgi?u1=/cgi-bin/v1.0/ask_for_money_page.cgi">收款</A> </LI>
<LI id=pay_g><A href="https://www.tenpay.com/cgi-bin/v1.0/jump.cgi?u1=/cgi-bin/v1.0/pay_money_page.cgi">付款</A> </LI>
<LI id=safement_g><A href="https://www.tenpay.com/cgi-bin/v1.0/jump.cgi?u1=/zft/tenpay_safe.shtml">安全中心</A> </LI>
<LI id=service_g class=lastNav><A href="https://www.tenpay.com/zft/admin_opentrans.shtml">商家服务</A> </LI></UL></DIV>
<SCRIPT type=text/javascript>TFL.header.initHeader();</SCRIPT>
</DIV><!-- end header --><!-- wrap start -->
<DIV id=wrap>
 

<DIV style="DISPLAY: block" id=s class="summary dhide">
<DIV class=summary-wrap>
<DIV class=em-info><SPAN class=trade-intro>本次交易为即时到账交易,货款将直接支付给卖家无“确认收货操作”</SPAN> 来自<STRONG>北京华远互通科技有限公司</STRONG>的交易</DIV>
<DIV class=trade-title>
<P>商品名称:<LABEL id=trade-switch class=t-close><A class=h href="https://www.tenpay.com/cgi-bin/v1.0/pay.cgi#">查看交易详情</A></LABEL><A style="COLOR: #07679c; TEXT-DECORATION: underline" id=trade-exhibit class=close-list onmouseover="this.style.color='#ff7e00'" onmouseout="this.style.color='#07679c'">15012345678用户充值话费10元</A></P>


<DL id=trade-list>
<DT>商品名称: 
<DD>15012345678用户充值话费10元 </DD>
<DT>交易对方: 
<DD>北京华远互通科技有限公司 </DD>
<DT>交易类型: 
<DD>即时到账交易 </DD>
<DT>订单号: 
<DD>1210969201201301310218524980 </DD>
<DT>商户订单号: 
<DD>A1WT2013013120360450471282 </DD>
<DT>商品价格: 
<DD>9.70 </DD></DL>
<DIV class=desc-info><SPAN style="DISPLAY: none" id=us_exchange_rate class=us-exchange-rate>汇率:1.00&nbsp;<SPAN id=trans_rate_name></SPAN>&nbsp;=&nbsp;<SPAN id=trans_rate></SPAN>&nbsp;人民币&nbsp;&nbsp;&nbsp;&nbsp;中国建设银行&nbsp;&nbsp;<SPAN id=trans_rate_time></SPAN>日报价</SPAN>应付金额:<INS id=amount class=fee>9.70<SUB> 元</SUB></INS> <SPAN style="DISPLAY: none" id=fee_us class=fee-us>(<SPAN id=currency_type></SPAN>&nbsp;<SPAN id=foreign_fee></SPAN>)</SPAN> </DIV></DIV></DIV></DIV>
<DIV id=d class="summary dhide">
<P class=strong>本次{pay_text}<STRONG id={strong_id}>{pay_amount}<SUB> 元</SUB></STRONG><!--{pay_to_text}<span id="{span_id}"> {b_true_name}</span>--></P>
<DIV class=trade-title>
<P>{pay_memo_text}<LABEL id={label_id} class=t-close><A class=h href="#">查看交易详情</A></LABEL><A style="COLOR: #07679c; TEXT-DECORATION: underline" id={a_id} class=close-list onmouseover="this.style.color='#ff7e00'" onmouseout="this.style.color='#07679c'">{desc}</A></P>
<DL id={dl_id}>
<DT>{dt1} 
<DD>{desc} 
<DT>{dt2} 
<DD>{b_true_name} 
<DT>{dt3} 
<DD>{b_id} 
<DT>{dt4} 
<DD>{dd4} 
<DT>{dt5} 
<DD>{transaction_id} 
<DT>{dt6} 
<DD>{price} 
<DT>{dt7} 
<DD>{transport_fee} 元 </DD></DL></DIV></DIV>
<DIV id=s1 class="summary dhide">
<P class=strong>本次{pay_text}<STRONG id={strong_id1}>{pay_amount}<SUB> 元</SUB></STRONG>{pay_to_text}<SPAN id={span_id1}> {b_true_name}</SPAN></P>
<DIV class=trade-title>
<P>{pay_memo_text}<LABEL id={label_id1} class=t-close><A class=h href="#">查看交易详情</A></LABEL><A style="COLOR: #07679c; TEXT-DECORATION: underline" id={a_id1} class=close-list onmouseover="this.style.color='#ff7e00'" onmouseout="this.style.color='#07679c'">{desc}</A></P>
<DL id={dl_id1}>
<DT>{dt1} 
<DD>{b_true_name} 
<DT>{dt2} 
<DD>{desc} 
<DT>{dt3} 
<DD>{price} 
<DT>{dt4} 
<DD>{transaction_id} </DD></DL></DIV></DIV>
<DIV id=s2 class="summary dhide">
<P class=strong>本次邮政汇款交易额<STRONG id={strong_id2}>{pay_amount}<SUB> 元</SUB></STRONG></P>
<DIV class=trade-title>
<P>{pay_memo_text}<LABEL id={label_id2} class=t-close><A class=h href="#">查看交易详情</A></LABEL><A style="COLOR: #07679c; TEXT-DECORATION: underline" id={a_id2} class=close-list onmouseover="this.style.color='#ff7e00'" onmouseout="this.style.color='#07679c'">交易详情</A></P>


<DL id={dl_id2}>
<DT>{dt1} 
<DD>{desc} 
<DT>{dt2} 
<DD>{transaction_id} 
<DT>{dt3} 
<DD>{hAmount} 元 
<DT>{dt4} 
<DD>{sFee} 元 
<DT>{dt5} 
<DD>{hFee} 元 
<DT>{dt6} 
<DD>{b_true_name} </DD></DL></DIV></DIV><!-- 混合支付 [[  -->
<DIV id=pay-mix class=form>
<DIV class=yh-mix><SPAN id=yh_use><SPAN id=caibei>登录后可使用彩贝积分及优惠券抵扣现金。</SPAN><BUTTON id=btn-yh>登录</BUTTON></SPAN> <SPAN id=yh_line><LABEL class=label>订单金额:</LABEL><INS id=ord_fee class=ord-fee>1.00</INS>元&nbsp;&nbsp;&nbsp;&nbsp;<LABEL class=label>抵扣:</LABEL><INS id=yh_fee class=yh-fee>2.00</INS>元</SPAN> </DIV>
<DIV id=no_discount>您没有用于本次交易的积分和优惠券。</DIV>
<DIV id=use-score>
<DIV id=pay-score class=line><LABEL class=label>使用彩贝积分:</LABEL> <SPAN id=score_enough><INPUT id=iptScore class="std xshort" value=0> 分,<A id=link-useAllScore href="###">使用全部</A> </SPAN><SPAN id=score_msg></SPAN>(当前可用积分 <STRONG id=score>0</STRONG> 分) <INS id=err-score class=errorinfo>您的积分不足</INS> </DIV><SPAN id=no-score>您暂时没有彩贝积分</SPAN> </DIV>
<DIV id=use-voucher>
<DIV id=voucher-list class=line><LABEL class=label>使用优惠券:</LABEL><SPAN id=voucher><SELECT><OPTION selected>财付通现金券 | 面额:10元 | 有效期至:2010-12-23</OPTION></SELECT></SPAN> <SPAN id=v-offset></SPAN><SPAN id=voucher></SPAN></DIV>
<DIV id=no-voucher><LABEL class=label>使用优惠券:</LABEL>您没有可用于本次交易的优惠券。</DIV></DIV></DIV><!-- 混合支付 ]]  -->
 
 

正则表达式
[解决办法]
订单号:\s+\r\n\<DD\>(\d+)\s+?\<\/DD\>

商户订单号:\s+\r\n\<DD\>(\d+)\s+?\<\/DD\>
[解决办法]
该页中的订单号有唯一性,比较好找用提取组的方法
正则可以用

string html=以上代码;
regex ddreg = new regex(@"<DT>订单号:<DD>(?<DDH>[\d]*)</DD><DD>(?<shddh>[\d]*)</DD>");
string ddh = ddreg.match(html).group["DDH"].value;   //这个得到的就是订单号
string shddh =ddreg.match(html).group["shddh"].value;  //这个得到的就是商户订单号
 
[解决办法]
(?is)<DT>订单号:\s*<DD>(.*?)</DD>\s*<DT>商户订单号:\s*<DD>(.*?)</DD>

string html=yourHtml;
regex reg = new regex(@"(?is)<DT>订单号:\s*<DD>(.*?)</DD>\s*<DT>商户订单号:\s*<DD>(.*?)</DD>");

string orderID = reg.Match(html).Group[1].Value;   //这个得到的就是订单号
string orderSellerID =reg.Match(html).Group[2].Value;  //这个得到的就是商户订单号

[解决办法]

  string str = File.ReadAllText("D:\\1.txt", Encoding.Default);
            var ary = Regex.Matches(str, @"(?is)(?<=(商户)?订单号[::]\s*<DD>\s*)[a-z0-9]+(?=\s*</DD>)").OfType<Match>().Select(t => t.Value).ToList();


           

热点排行