Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /** * Takes the characters until the pattern is matched */ public static String takeUntil(Object src, Object pattern) { String src2 = src.toString(); Matcher matcher = Pattern.compile(pattern.toString()).matcher(src2); if (!matcher.find()) return src2; int index = matcher.start(); if (index == -1) { return src2; } return src2.substring(0, index); } }