正则表达式在匹配后替换所有内容
我有以下文本文件内容:
<?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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(?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