import Foundation
let pattern = #"(['""])((?:\\1|(?:(?!\1)).)*)(\1)|(?<OpenMatch>({))|(?<CloseMatch>(}))"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
if (!(new[] { "Command", "Click" }).Any(d => xmlAttribute.Name.Equals(d,
StringComparison.CurrentCultureIgnoreCase))) continue;
if (!baseChain.Name.Contains(':')) return chain;
var checkAnyInherited = baseChain.Name.Split(':').Last().Split(',', ' ').Where(d => !string.IsNullOrEmpty(d)).Select(d => d.Trim()).ToList();
private static IEnumerable<StatementReferenceMaster> GetAllMethodsForClass(string className, int projectId)
{
using (ICodeVortoService codeVortoService = new CodeVortoService())
{
object[] parametersExp =
{
new MySqlParameter("@delim", MySqlDbType.VarChar) {Value = ","},
new MySqlParameter("@className", MySqlDbType.VarChar) {Value = className},
new MySqlParameter("@prjId", MySqlDbType.Int32) {Value = projectId}
};
var callExtExpandedCode = codeVortoService.StatementReferenceMasterRepository
.ExecuteStoreProcedure<StatementReferenceMaster>("SpGetAllMethodsForClass", parametersExp)
.ContinueWith(t => t.Result).Result;
return callExtExpandedCode;
}
}
@"CREATE\s+TABLE"
@"\`(.*?)\`\s+\("
@"^\`(.*?)\`(.*)"
@"^PRIMARY\s+KEY"
@"(.*)\((.*)\)"
""
""
""
"("
"-"
"DbScript"
@"CREATE\s+TABLE\s+(\[dbo\].)?(\[)?(\`)?(?<TableName>[a-zA-Z0-9_$]+)(\])?(\`)?"
@"^([\s]+)?(\[|\`)?(?<FieldName>[a-zA-Z0-9_$]+)(\]|\`)?"
"TableName"
@"C:\inetpub\wwwroot\flokapture\ExtractedProjects\LocationServicesSource\Pods.Integration.Services.Location.Model\LocationServiceModel.edmx"
@"^<EntityContainer\s+Name=\""([^\""]*)\"""
@"^<EntityType\s+Name=\""([^\""]*)\"""
@"StoreEntitySet=\""([^\""]*)\"""
@"^<Property\s+"
@"^<EntityType\s+Name=\""([^\""]*)\""|^<Property\s+|^</EntityType>\s+"
"<edmx:Mappings>"
"</EntityType>"
"Done"
"SELECT * FROM EntityAttributes WHERE ProjectId = "
" Group by EntityName;"
@"(?<VariableName>[a-z_]+)\s*=\s*new\s+[a-z.0-9]+?"
"\\(\\)|[\\s]*[\\w]+\\s+(?<VariableName>[a-zA-Z0-9$_]+)[\\s]*=[\\s]*"
"."
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let matches = regex.matches(in: testString, range: stringRange)
var result: [[String]] = []
for match in matches {
var groups: [String] = []
for rangeIndex in 1 ..< match.numberOfRanges {
let nsRange = match.range(at: rangeIndex)
guard !NSEqualRanges(nsRange, NSMakeRange(NSNotFound, 0)) else { continue }
let string = (testString as NSString).substring(with: nsRange)
groups.append(string)
}
if !groups.isEmpty {
result.append(groups)
}
}
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