Chinaunix

标题: Perl如何克服这样的贪婪匹配 [打印本页]

作者: feiying00917    时间: 2014-07-13 22:33
标题: Perl如何克服这样的贪婪匹配
本帖最后由 feiying00917 于 2014-07-14 09:15 编辑

#!/usr/bin/perl -w
open (FILE,">test.txt";
#if ($_=~/^\text\:bookmark text\:name=\"\_\_RefNumPara\_\_80266\_1546026487\"\/\>([\s\<\>\w\d\.\'\(\)\/\"\:]+)\<text\:bookmark\-end text\:name\=\"\_\_RefNumPara\_\_80266\_1546026487\"\/\>/)
$_='<text:bookmark text:name="__RefNumPara__80266_1546026487"/><text:span text:style-name="T22">On schematic page 42, the pin CSPBAVE (7) of instance U58 (MAXIM – </text:span><text:bookmark-start text:name="__DdeLink__60226_1521216572"/><text:span text:style-name="T22">MAX17611) is connect to </text:span><text:bookmark-end text:name="__DdeLink__60226_1521216572"/><text:span text:style-name="T22">CSBN(N-side), while the device datasheet (MAX17611_DS.pdf – Page23) indicates &apos;Connect CSPBAVE to the positive side of the differential output of the external current-sense averaging network&apos;. Recommend connecting this pin to positive side pin CSPB1 (. <text:s/>(Major)</text:span><text:bookmark-end text:name="__RefNumPara__80266_1546026487"/>';
if ($_=~/\<text\:bookmark text\:name=\"\_\_RefNumPara\_\_80266\_1546026487\"\/\>(.+)\<text\:bookmark\-end text\:name\=\"\_\_RefNumPara\_\_80266\_1546026487\"\/\>/)
{
        $1=s/\<.*\>?//g;
        print FILE $1;}
我要把<>和里面的内容去掉,可是我用这样的匹配$1=s/\<.*\>?//g; 最后得到的是空,该如何做,求帮忙!
作者: q1208c    时间: 2014-07-14 07:07
  1. s/\<.*?\>//g;
复制代码

作者: feiying00917    时间: 2014-07-14 10:28
多谢,可以了回复 2# q1208c


   
作者: yestreenstars    时间: 2014-07-14 10:40
不知道楼主为什么要在>后面加个问号
作者: q1208c    时间: 2014-07-14 11:14
回复 4# yestreenstars

或许楼主想把这一行全干掉.

   
作者: yestreenstars    时间: 2014-07-14 11:22
回复 5# q1208c

好吧~
   
作者: feiying00917    时间: 2014-07-14 21:56
没有经验啊,真的是全部干掉了,可以解释下吗回复 5# q1208c


   
作者: q1208c    时间: 2014-07-15 07:50
回复 7# feiying00917

>? 表示 有没有 这个 > 都可以. 如果这样, 那么, 前面的 .* 就可以直接匹配到行尾了.
   
作者: feiying00917    时间: 2014-07-15 16:12
多谢,可以加你QQ友吗?回复 8# q1208c


   
作者: q1208c    时间: 2014-07-15 17:14
回复 9# feiying00917

我们公司不让用 QQ.
   
作者: feiying00917    时间: 2014-07-15 17:46
那就邮箱吧,天天对着Perl,天天一大推问题回复 10# q1208c


   
作者: q1208c    时间: 2014-07-15 18:57
回复 11# feiying00917

你可以在这里发贴, 会有很多人帮助你的.
   
作者: feiying00917    时间: 2014-07-15 20:56
主要为了沟通比较即时和清楚回复 12# q1208c


   
作者: q1208c    时间: 2014-07-16 07:57
回复 13# feiying00917

perl 应该算是一门入门比较简单的语言.
我只是一般的用用. 想写出很高效的代码, 需要更多的经验, 我也是来跟这里的高手学习的.
   




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2