import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\s*\\d+\\s*(?:units?|times?(?:\\s+(?:a|per)\\s+|\\s*/\\s*)(?:d(?:ay)?|w(?:ee)?k|month|y(?:ea)?r?))";
final String string = "inJECTable 1234 Eprex DOSE 4000 units on NONd\n"
+ "department 6789 DOSE 8000 units on DIALYSIS days - IV Interm',\n"
+ "inJECTable 4321 Eprex DOSE - 3 times/wk on NONdialysis day',\n"
+ "insulin MixTARD 30/70 - inJECTable 46 units',\n"
+ "insulin ISOPHANE -- InsulaTARD Vial - inJECTable 56 units SC SubCutaneous',\n"
+ "1-alfacalcidol DOSE 1 mcg - 3 times a week - IV Intermittent',\n"
+ "jevity liquid - FEEDS PO Jevity - 237 mL - 1 times per day',\n"
+ "1-alfacalcidol DOSE 1 mcg - 3 times per week - IV Intermittent',\n"
+ "1-supported DOSE 1 mcg - 1 time/day - IV Intermittent',\n"
+ "1-testpackage DOSE 1 mcg - 1 time a day - IV Intermittent\n\n"
+ "///3 times a day, 3 time/wk, 3 times per day, 3 times a month, 3 times/month";
final String subst = "";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html