如何在 PERL 中使用正则表达式从字符串中删除特定的字符集

发布于 2024-09-11 05:26:49 字数 144 浏览 1 评论 0原文

1)例如::我有一个 $string ="abc hell_+o w343r2d -000 rebotin"。使用搜索模式和正则表达式有什么方法可以从 PERL 中的字符串中删除或删除 -000 。 2)我想以简单的方式开始通过示例学习正则表达式。哪个是最好的入门教程???

1)For example::I have a $string ="abc hell_+o w343r2d -000 rebotin".Using search pattern and regular expression is there any way to remove or chop -000 from the string in PERL.
2)I want to begin learning regular expression with examples in simple means.Which is the best tutorial to start with???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你又不是我 2024-09-18 05:26:49
$string = "foobar";
$string =~ s/bar/baz/g;

print $string 然后会产生“foobaz”,

s/foo/bar/g 语法称为 搜索并替换。第一项是要搜索的内容,第二项是要替换的内容。

在您的情况下,您希望替换子句为空以删除内容。 $string =~ s/-000//g 将完全删除 -000

$string = "foobar";
$string =~ s/bar/baz/g;

print $string would then yield "foobaz"

the s/foo/bar/g syntax is called search and replace. The first item is the thing to search for, second item is the thing to replace it with.

in your case, you'd want the replace clause to be empty for removing things. $string =~ s/-000//g would remove -000 completely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文