import Foundation
let pattern = #"public ([\w><]+ [\w><]+\(\))\s+{[^}]+}"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
using System.Linq;
using NineYi.ERPV2.DA.AppDB.Tables;
namespace NineYi.ERPV2.DA.Repositories.DbRepositories
{
/// <summary>
/// AppDbRepository
/// </summary>
public class AppDbRepository : IAppDbRepository
{
/// <summary>
/// AppDbContext
/// </summary>
private AppDbContext _appDbContext;
/// <summary>
/// Initializes a new instance of the <see cref="AppDbRepository" /> class.
/// </summary>
/// <param name="appDbContext">AppDbContext</param>
public AppDbRepository(AppDbContext appDbContext)
{
this._appDbContext = appDbContext;
}
/// <summary>
/// SaveChanges
/// </summary>
public void SaveChanges()
{
this._appDbContext.SaveChanges();
}
/// <summary>
/// QueryUserCoupons
/// </summary>
/// <returns>UserCoupons</returns>
public IQueryable<user_coupon> QueryUserCoupons()
{
return this._appDbContext.user_coupon;
}
/// <summary>
/// QueryPubContents
/// </summary>
/// <returns>PubContents</returns>
public IQueryable<pub_content> QueryPubContents()
{
return this._appDbContext.pub_content;
}
}
}
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"\1;"#
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
print(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 Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression