【发布时间】:2013-12-01 14:59:23
【问题描述】:
我将提取带有引号的 bbcode,但在实际输出到来时无济于事。
我想实现 bbcode 解析模块来提取所需的输出引号。引号的数量应该是递归方法或其他一些..
INput :
Testing [quote]http://www.yourube.com?watch?v=asasdsadsa [url] aisa [/url] [/quote] Testing
Desired Output
测试 http://www.yourube.com?watch?v=asasdsadsa [url] aisa [/url] 艾萨 测试
Actual Output:
http://www.yourube.com?watch?v=asasdsadsa [url] aisa [/url]
http://www.yourube.com?watch?v=asasdsadsa aisa
下面是我的代码
String s = "[quote]http://www.yourube.com?watch?v=asasdsadsa [url] aisa [/url][/quote]";
String t = bbcode(s);
System.out.println(t);
String u = bbcode2(t);
System.out.println(u);
public static String bbcode(String text) {
String html = text;
HashMap<String,String> bbMap = new HashMap<String , String>();
bbMap.put("\\[quote\\](.+?)\\[/quote\\]", "$1");
for (Map.Entry entry: bbMap.entrySet()) {
html = html.replaceAll(entry.getKey().toString(), entry.getValue().toString());
}
return html;
}
public static String bbcode2(String text) {
String html = text;
HashMap<String,String> bbMap = new HashMap<String , String>();
bbMap.put("\\[quote\\](.+?)\\[/quote\\]", "$1");
bbMap.put("\\[url\\](.+?)\\[/url\\]", "$1");
for (Map.Entry entry: bbMap.entrySet()) {
html = html.replaceAll(entry.getKey().toString(), entry.getValue().toString());
}
return html;
}
【问题讨论】:
-
你是在解析html吗?
-
不,我使用“$1”提取标签内的原始内容
-
你能解释一下这个程序应该做什么吗?
-
请阅读输入并希望输出。我将用bbcode解析内容,提取bbcode所包含的所有内容进行内容管理
-
你的问题是
bbcode2()吗?