perl不用新线来串通字符串
我在perl上的字符字符号遇到了这个问题。我的目标是删除所有“”。和“ - ”我的XML。它与前4个标签搭配得很好,但不会删除“”。和“ - ”描述标签上具有新的内容。
这是我的代码:
/>([^\000]*?)</g;
$lastp = $1;
$lastp =~ s/[\.|\-]*?//g;
$_ =~ s/(>)[^\000]*?(<)/$1$lastp$2/g;
这是我的示例数据:
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>.44.95......</price>
<publish_date>200.0-10-
01.</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
这是我的输出:
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>4495</price>
<publish_date>200.0-10-
01.</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
I have this problem with subtituting characters on perl. My goal is to remove every "." and "-" on my xml. It goes well with the first 4 tags, but it doesnt remove the "." and "-" on the description tag that has a newline on its content.
This is my code:
/>([^\000]*?)</g;
$lastp = $1;
$lastp =~ s/[\.|\-]*?//g;
$_ =~ s/(>)[^\000]*?(<)/$1$lastp$2/g;
This is my sample data:
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>.44.95......</price>
<publish_date>200.0-10-
01.</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
And here is my output:
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>4495</price>
<publish_date>200.0-10-
01.</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能否尝试以下内容:
输出:
(?
零宽度lookbehind主张
&gt;
和[^&lt;]+
匹配除了
&lt;
以外的任何字符的顺序。然后分配变量$&amp;
到匹配的子字符串。
我的$ s = $&amp ;; $ s = 〜s#[ - 。] ## g; $ s
删除-
和。
匹配的子字符串。然后修改的字符串
$ s
用作替换
s/stater/替换/
操作员的 E e 选项。Would you please try the following:
Output:
(?<=>)[^<]+
matches a string between tags:(?<=>)
is azero width lookbehind assertion of leading
>
and[^<]+
matches thefollowing sequence of any characters except for
<
. Then the variable$&
is assignedto the matched substring.
my $s = $&; $s =~ s#[-.]##g; $s
removes-
and.
from thematched substring. Then the modified string
$s
is used as thereplacement
of thes/pattern/replacement/
operator thanks to thee
option.