java替换表情符号 求正则表达式替换
符号格式[a01][a02][b01][b02]分别替换为<imgsrc='../image/a01.png'/><imgsrc='../image/a02.png'/>...
符号格式 [a01] [a02] [b01] [b02] 分别替换为<img src='../image/a01.png'/> <img src='../image/a02.png'/> <img src='../image/b01.png'/> <img src='../image/b02.png'/>
展开
2015-02-13
展开全部
package test;
public class YuGiOh
{
public static void main ( String[] args )
{
String src = "[a01] [a02] [b01] [b02]";
String regex = "\\[([^\\[\\]]+)\\]";
System.out.println (src.replaceAll (regex, "<img src='../image/$1.png' />"));
}
}
追问
中括号里面的只能是a01到a26 b01到b28 这么能不能放表达式里限制
追答
public class YuGiOh
{
public static void main ( String[] args )
{
String src = "[a01] [a27] [b15] [b27]";
String regex = "\\[((a|b)(0[1-9]|1\\d|2[0-6])|b2[78])\\]";
System.out.println (src.replaceAll (regex, "<img src='../image/$1.png' />"));
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询