Here you can find the source of removeMatchingRegex(String regex, String replacement, String[] tokens, boolean removeEmpty)
public static String[] removeMatchingRegex(String regex, String replacement, String[] tokens, boolean removeEmpty)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; public class Main { /**// w ww . j av a2s .c o m * Applies given regex on tokens and may optionally delete when a token gets * empty. */ public static String[] removeMatchingRegex(String regex, String replacement, String[] tokens, boolean removeEmpty) { String[] tk = new String[tokens.length]; for (int i = 0; i < tokens.length; i++) { tk[i] = tokens[i].replaceAll(regex, replacement); } if (removeEmpty) { tk = removeEmpty(tk); } return tk; } /** * Removes empty tokens from given array. The empty slots will be filled with * the follow-up tokens. */ public static String[] removeEmpty(String[] arr) { ArrayList<String> list = new ArrayList<>(); for (String s : arr) { if (s != null && !s.isEmpty()) list.add(s); } return list.toArray(new String[list.size()]); } }