import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = ".*-> addField\\(('\\S*').*?, \\['type' => new (\\S*?)Type.*";
final String string = "-> addField('id' , ['type' => new IntType , 'description' => __('id')])\n"
+ " -> addField('type_mandaat' , ['type' => new StringType , 'description' => __('type mandaat')])\n"
+ " -> addField('bedrag' , ['type' => new BedragType , 'description' => __('bedrag')])\n"
+ " -> addField('datum_expertise_plaatsgevonden' , ['type' => new DateType , 'description' => __('datum van expertise')])\n"
+ " -> addField('datum_ontvangst_rapport' , ['type' => new DateType , 'description' => __('datum van ontvangst rapport')])\n"
+ " -> addField('omschrijving' , ['type' => new StringType , 'description' => __('omschrijving')])\n"
+ " -> addField('wrakwaarde' , ['type' => new BedragType , 'description' => __('wrakwaarde')])\n"
+ " -> addField('forfait' , ['type' => new BooleanType , 'description' => __('forfait')])\n"
+ " -> addField('total_loss' , ['type' => new BooleanType , 'description' => __('total loss')])\n"
+ " -> addField('kosten_expertise' , ['type' => new FloatType , 'description' => __('kosten expertise')])\n"
+ " -> addField('experts' , ['type' => new ListType(new ExpertInput), 'description' => __('experts')]);";
final String subst = "\\1 => ['type' => '\\2'],";
final Pattern pattern = Pattern.compile(regex);
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