From faf709b4141f52cdd04a02edad31bf62a32af824 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Mon, 20 Feb 2012 22:27:44 +0700 Subject: regexLinks2 Thank's to @Kim --- src/java/com/juick/http/www/PageTemplates.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/java/com/juick/http/www') diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index b7b2f536..90246e76 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -27,6 +27,8 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Locale; import java.util.ResourceBundle; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; import ru.sape.Sape; @@ -241,6 +243,7 @@ public class PageTemplates { public static String formatReplies(int replies, Locale loc) { return replies + " repl" + (replies % 10 == 1 ? "y" : "ies"); } + private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?juick.com) - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))([\\(\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"\\)\\!]+)/?[^\\s]*)([\\)\\]\\}]|>)", "$1$2$4$5"); + Matcher m = regexLinks2.matcher(msg); + StringBuffer sb = new StringBuffer(); + while (m.find()) { + String url = m.group(3).replace(" ", "%20").replaceAll("\\s", ""); + m.appendReplacement(sb, "$1$2$4$5"); + } + m.appendTail(sb); + msg = sb.toString(); // > citate - msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))>\\s(.*)(\\n|(?=\\Z))", "
$1
"); + msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))>\\s*(.*)(\\n|(?=\\Z))", "
$1
"); msg = msg.replaceAll("
", "\n"); msg = msg.replaceAll("\n", "
\n"); -- cgit v1.2.3