gpt4 book ai didi

java - 如何从大量文本内容中提取特定文本?

转载 作者:太空宇宙 更新时间:2023-11-04 12:39:02 25 4
gpt4 key购买 nike

我有一个段落

Dear testUser testUser, 
You have been registered in the Request Management System.
Your username is the email address to which this notification is addressed.
Please click the link below to set your password: http://www.example.com/QA/ChangePassword.aspx?userName=example@yopmail.com&tempPassword=b0cb6ca7-2e52-4b80-8252-f5dac499cea3
You will receive further information from the our employee that has registered you in the system.
Thank you

在上面的段落中,我想提取用于生成新密码的 URL。

我为此使用了正则表达式,并且能够实现一些目标。

下面是我使用的代码

String REGEX="Dear testuser,testuser,|You have been registered in the Request Management System.|Your username is the email address to which this notification is addressed.|Please click the link below to set your password:|You will receive further information from the our employee that has registered you in the system.|Thank you";
if(copiedText.contains("password"))
{
copiedText=copiedText.replaceAll(REGEX, "").trim();
System.out.println("Final Text after replace: "+copiedText);
keyValues.put(key,copiedText);
System.out.println("the Values stored in map are:" + keyValues);

}

我正在使用此方法获取 URL,但我认为这不是一个好方法。我需要一些通用的解决方案,因为用户名也会在实时场景中发生变化。那么我们如何在 java 中处理这个问题。

最佳答案

您可以使用吐出字符串

String expe= "Dear testUser testUser,"
+ "You have been registered in the Request Management System. "
+ "Your username is the email address to which this notification is addressed. "
+ "Please click the link below to set your password: http://www.example.com/QA/ChangePassword.aspx?userName=example@yopmail.com&tempPassword=b0cb6ca7-2e52-4b80-8252-f5dac499cea3"
+ "You will receive further information from the our employee that has registered you in the system."
+ "Thank you";


String[] parts = expe.split("your password: ");
String part2 = parts[1];
parts = part2.split("You will receive further information");
part2 = parts[0];
System.out.println(part2);

您将轻松获得所需的 URL。

关于java - 如何从大量文本内容中提取特定文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37019022/

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