Monday, July 30, 2018

searching of digit from string using regex and replace from Java String.

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class regex{

public static void main(String []args){
    System.out.println("Hello World");
    String s = "214投資者、43発行者";
    Pattern p = Pattern.compile("([0-9]+)");
    Matcher m = p.matcher(s);
    int index = 0;
    StringBuffer str = new StringBuffer();
    while (m.find()){

        String match = m.group();
        m.appendReplacement(str,"replace"+">");

    }
    m.appendTail(str);
    String result = str.toString();
    System.out.println(result);


   }
}

No comments:

Post a Comment