Neighborhoods: Find a regular expression, changed into a standard label.

Category: Web Develop
 
xiaojingyuan1993
2011-03-10 08:29:29

Sponsored Links
	public static void main(String[] args) {
// TODO Auto-generated method stub
String conet=sd.encodeContent("<img src="aaa.jpg" alt="" />");
System.out.println("result:"+conet);
}
public static String encodeContent(String content){
while(content.matches(".*[img].*[//img].*")){
System.out.println(content);
//content=content.replaceAll("//[img//].*//[///img//]", "<img src=''></img>");
String src=content.substring(content.indexOf("[img]")+5, content.indexOf("[/img]"));
content=content.replaceFirst("[img].*[//img]", "<img src='"+src+"'></img>");
System.out.println("1:"+content);
}
return content;
}

Sponsored Links

qwe63216
2011-03-10 08:46:43

public static String encodeContent(String content) {
content = content.replaceAll("\\[(img)\\](.*?)\\[(/img)\\]","<$1>$2<$3>");
return content;
}
fanny797
2011-03-10 08:56:08

Thank you. Thank you very much. I follow your approach. Doing other labels. Question asking you.
walkfreely
2011-03-10 09:01:55

in to ask:
I now want [code] class [/ code], becomes <pre name = 'code' class = 'java' > class </pre>, how to do it?
I follow your kind of approach is to do so,
	public static String encodeCode(String content) {
    content = content.replaceAll("\\[(code)\\](.*?)\\[(/code)\\]","<pre name='code' class='java'>$2
");
    return content;
}</pre>
, but if the code and / code, not in the same line, it will output as in the same line, it will generate code highlighting effect, does this how to solve it?
A844187338
2011-03-10 09:22:28
how Meirenhuida ah?
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.