import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "public ([\\w><]+ [\\w><]+\\(\\))\\s+\\{[^\\}]+\\}";
final String string = "using System.Linq;\n"
+ "using NineYi.ERPV2.DA.AppDB.Tables;\n\n"
+ "namespace NineYi.ERPV2.DA.Repositories.DbRepositories\n"
+ "{\n"
+ " /// <summary>\n"
+ " /// AppDbRepository\n"
+ " /// </summary>\n"
+ " public class AppDbRepository : IAppDbRepository\n"
+ " {\n"
+ " /// <summary>\n"
+ " /// AppDbContext\n"
+ " /// </summary>\n"
+ " private AppDbContext _appDbContext;\n\n"
+ " /// <summary>\n"
+ " /// Initializes a new instance of the <see cref=\"AppDbRepository\" /> class.\n"
+ " /// </summary>\n"
+ " /// <param name=\"appDbContext\">AppDbContext</param>\n"
+ " public AppDbRepository(AppDbContext appDbContext)\n"
+ " {\n"
+ " this._appDbContext = appDbContext;\n"
+ " }\n\n"
+ " /// <summary>\n"
+ " /// SaveChanges\n"
+ " /// </summary>\n"
+ " public void SaveChanges()\n"
+ " {\n"
+ " this._appDbContext.SaveChanges();\n"
+ " }\n\n"
+ " /// <summary>\n"
+ " /// QueryUserCoupons \n"
+ " /// </summary>\n"
+ " /// <returns>UserCoupons</returns>\n"
+ " public IQueryable<user_coupon> QueryUserCoupons()\n"
+ " {\n"
+ " return this._appDbContext.user_coupon;\n"
+ " }\n\n"
+ " /// <summary>\n"
+ " /// QueryPubContents \n"
+ " /// </summary>\n"
+ " /// <returns>PubContents</returns>\n"
+ " public IQueryable<pub_content> QueryPubContents()\n"
+ " {\n"
+ " return this._appDbContext.pub_content;\n"
+ " }\n"
+ " }\n"
+ "}";
final String subst = "\\1;";
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