正则表达式在匹配后替换所有内容

发布于 2024-12-05 06:20:25 字数 630 浏览 6 评论 0原文

我有以下文本文件内容:

<?php
//================ Versions ================
$applicatoinversion = '1.2.3.40';
$someothervariable = 'td11';

$dbversion = '2.3.1.4';

Other code here
?>

我需要将除(应用程序)版本号之外的所有内容替换为空字符串。因此,我可以保存以下文件:

1.2.3.40

我没有使用编程语言,因此我只需要使用正则表达式替换来完成此操作。

到目前为止可以匹配版本号:

(?<=\$applicatoinversion = \')(([0-9]\.){1,3}([0-9])+)(?=\';)

并设法匹配之前的所有内容:

(.|\n)*(?=
(?<=\$applicatoinversion = \')(([0-9]\.){1,3}([0-9])+)(?=\';)
)

但我被卡住了。我无法匹配版本号之前和之后的所有内容。这里有高手吗?

提前致谢

I have the following text file content:

<?php
//================ Versions ================
$applicatoinversion = '1.2.3.40';
$someothervariable = 'td11';

$dbversion = '2.3.1.4';

Other code here
?>

I need to replace everything EXCEPT the (application) version number with an empty string. So I can save the following file:

1.2.3.40

I'm not using a programmig language so I need to do it only with regular expression replace.

So far can match the version number:

(?<=\$applicatoinversion = \')(([0-9]\.){1,3}([0-9])+)(?=\';)

And managed to match everything before:

(.|\n)*(?=
(?<=\$applicatoinversion = \')(([0-9]\.){1,3}([0-9])+)(?=\';)
)

But I'm stuck. I cant match everything BEFORE and AFTER version number. Any gurus here?

Thanks in advance

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

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

发布评论

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

评论(1

唔猫 2024-12-12 06:20:25

(?s).*applicatoinversion = '(([0-9]\.){1,3}([0-9])+)'.*

只需将所有内容替换为第1组

(?s).*applicatoinversion = '(([0-9]\.){1,3}([0-9])+)'.*

just replace all with the match from group 1

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