我需要在网页上显示word文档。我正在使用名为Docx4j的库将.doc转换为html。这工作正常。但是,我以下面的格式获取超链接。如何使用正则表达式从URL中获取域名?
To search on google go to this link [#?] HYPERLINK \"http://www.google.com/\" [#?][#?] google[#?] and type the text.
我可以使用下面的代码,将其转换为
To search on google go to this link (http://www.google.com) google and type the text.
String myText = "To search on google go to this link [#?] HYPERLINK \"http://www.google.com/\" [#?][#?] google[#?] and type the text.";
System.out.println(myText);
String firstReplace = myText.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("#\\?", "");
System.out.println(firstReplace);
String secondReplace = firstReplace.replaceAll("HYPER\\S+\\s+\"", "(");
System.out.println(secondReplace);
String finalReplace = secondReplace.replaceAll("/*\".", ")");
System.out.println("\n" + finalReplace);
可有人请我提供一个正则表达式上面的字符串转换为
To search on google go to this link google (http://www.google.com) and type the text.
- EDIT--
有一些链接,其显示为
[#?] HYPERLINK \"http://www.google.com/\" [#?][#?] google page[#?]
我应该改变他们
google page (http://www.google.com)
我该怎么办呢?
可以请您详细说明吗? –
@SumodhS结帐编辑。 – Kasramvd
有什么方法可以让我“http://www.google.com/”直接替换为“(http://www.google.com/)”?我不能在这个问题中使用这个脚本,因为我拥有的是一个HTML并替换掉了“我的HTML –