gpt4 book ai didi

java - 只保留一个完整的 URL

转载 作者:行者123 更新时间:2023-12-01 11:12:05 25 4
gpt4 key购买 nike

我有一些内容除 URL 之外还包含以下格式的文本:

some text http://www.example.com/foo... <http://www.example.com/foo.html> some text

或这种格式:

some text http://www.example.com/bar <http://www.example.com/bar> some text

我需要清理它才能分别变成:

some text http://www.example.com/foo.html some text

和:

some text http://www.example.com/bar some text

有没有办法用正则表达式来实现这一点?

最佳答案

我通过using backreferences to match the same text again解决了这个问题:

input.replaceAll("(https?://([^ ]+))(\\.{3,3})? *<(\\1[^ ]+)>", "$4")

关于java - 只保留一个完整的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32229430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com