xml解析中的正则表达式
问题描述:
这是内容。xml解析中的正则表达式
<ext-link ext-link-type="uri" xlink:href="http://<xref rid="x0026;AN=15230473">http://web.ebscohost.coms/ehost/detail&#x003F;sid=d1f06770-cd74-4496-ae7b-7689ed05c6c4%40sessionmgr10&#x0026;vid=1&#x0026;hid=23&#x0026;bdata=JnNpdGU9ZWhvc3QtbGl2ZQ%3d%3d&#x0023;db=ufh&#x0026;AN=15230473</xref>" link-type="url">
我想里面的XLink捕获:HREF = “http://<xref rid="x0026;AN=15230473">http://web.ebscohost.coms/ehost/detail&#x003F;sid=d1f06770-cd74-4496-ae7b-7689ed05c6c4%40sessionmgr10&#x0026;vid=1&#x0026;hid=23&#x0026;bdata=JnNpdGU9ZWhvc3QtbGl2ZQ%3d%3d&#x0023;db=ufh&#x0026;AN=15230473</xref>
”
用双引号。
我试试这个,但不能得到我需要的。
<ext-link(?: [^>]+)? xlink:href="([^"]+)"[^><]*>
答
perl -pe 's/^.*xlink:href=\"//; s/\">$//' file
实施例:
[email protected]:~/AMD/SO$ cat file
<ext-link ext-link-type="uri" xlink:href="http://<xref rid="x0026;AN=15230473">http://web.ebscohost.coms/ehost/detail&#x003F;sid=d1f06770-cd74-4496-ae7b-7689ed05c6c4%40sessionmgr10&#x0026;vid=1&#x0026;hid=23&#x0026;bdata=JnNpdGU9ZWhvc3QtbGl2ZQ%3d%3d&#x0023;db=ufh&#x0026;AN=15230473</xref>">
[email protected]:~/AMD/SO$ perl -pe 's/^.*xlink:href=\"//; s/\">$//' file
http://<xref rid="x0026;AN=15230473">http://web.ebscohost.coms/ehost/detail&#x003F;sid=d1f06770-cd74-4496-ae7b-7689ed05c6c4%40sessionmgr10&#x0026;vid=1&#x0026;hid=23&#x0026;bdata=JnNpdGU9ZWhvc3QtbGl2ZQ%3d%3d&#x0023;db=ufh&#x0026;AN=15230473</xref>
答
一些其他属性也都在构造线后:HREF – depsai 2014-11-24 10:12:41
没有找到解决办法。 – depsai 2014-11-24 10:13:13
尝试以上... – 2014-11-24 10:14:19