import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^\\s*\\K\\w+";
final String string = "{\n"
+ " questions: [\n"
+ " {\n"
+ " name: \"name\",\n"
+ " type: \"text\",\n"
+ " title: \"Please enter your name:\",\n"
+ " placeHolder: \"Jon Snow\",\n"
+ " isRequired: true\n"
+ " }, {\n"
+ " name: \"birthdate\",\n"
+ " type: \"text\",\n"
+ " inputType: \"date\",\n"
+ " title: \"Your birthdate:\",\n"
+ " isRequired: true\n"
+ " }, {\n"
+ " name: \"color\",\n"
+ " type: \"text\",\n"
+ " inputType: \"color\",\n"
+ " title: \"Your favorite color:\"\n"
+ " }, {\n"
+ " name: \"email\",\n"
+ " type: \"text\",\n"
+ " inputType: \"email\",\n"
+ " title: \"Your e-mail:\",\n"
+ " placeHolder: \"jon.snow@nightwatch.org\",\n"
+ " isRequired: true,\n"
+ " validators: [\n"
+ " {\n"
+ " type: \"email\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " ]\n"
+ "}";
final String subst = "\"\\0\"";
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