服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

about ubb with java has a bug.


  // the bug has been fixed
/*+-------------------------------
    $rereplace.java 2001-9-4
    $author pizer.chen
    $history:
        0.2 fixed a bug.
        0.1 ...
+-------------------------------*/
package com.wacos.util.ubb;

import java.io.*;
import java.util.*;
import org.apache.regexp.*;
/**
*
* @author  pizer.chen -- iceant -- 陈鹏
* @version 0.2
*/
public class rereplace
{
    /**
     * replace the instr with pattern1 & pattern2
    **/
    public static string replace(string pattern1,string pattern2,string instr){
        try {
            re re = new re(pattern1);
            re re2 = new re("//$([0-9])");
            string temppat2=pattern2;
            int point=0;
            while(re.match(instr)){
                while(re2.match(pattern2)){
                    point = integer.parseint(re2.getparen(1));
                    pattern2=re2.subst(pattern2,re.getparen(point),re.replace_firstonly);
                }
                instr = re.subst(instr,pattern2,re.replace_firstonly);
                pattern2 = temppat2;
            }
            return instr;
        }
        catch (exception e) {
            system.out.println(e);
            return e.tostring();
        }  
    }
}    

扫描关注微信公众号