import Foundation
let pattern = ##".+(?=\sProject #)"##
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = ##"""
Return to Contents
Street Improvements
Ocotillo Road – Greenfield to Higley Project #: ST0540
Project Description:
Design and construction of Ocotillo Road from approximately ¼ mile east of Greenfield Road to Higley Road to
minor arterial standards. The project includes crossings over the Queen Creek Wash, East Maricopa Floodway,
Roosevelt Water Conservation District Canal and Chandler Heights Basin. The project includes the relocation of
69kV power lines and access into the proposed Gilbert Regional Park.
Project Information:
• Costs shown in prior years are for completion of an alignment study in FY 2009
to coordinate the alignment with Flood Control District projects
• Maintenance costs will be determined once final design is completed. Ongoing
maintenance costs will be a consideration in selection of the project design
• Project is necessary for growth/development and therefore is eligible for
System Development Fee funding
Financial Information:
Expenses: (1,000s) Total Prior FY 2021 FY 2022 FY 2023 FY 2024 FY 2025 Years 6- Beyond
Years 10 10 Yrs
Professional Services $ 6,104 299 5,805 - - - - - -
Construction Mgmt $ 4,316 33 4,283 - - - - - -
Land/ROW $ 2,325 - 2,325 - - - - - -
Construction $ 53,774 - - 53,774 - - - - -
Equipment & Furniture $ - - - - - - - - -
Total Expenses $ 66,519 $ 332 $ 12,413 $ 53,774 $ - $ - $ - $ - $ -
Sources: (1,000s)
2007 GO Bonds 08 $ 246 246 - - - - - - -
2022 Potential Street Bond $ 50,701 - - 50,701 - - - - -
CIP O/S Revolving Fund $ 375 86 289 - - - - - -
Roads SDF $ 15,197 - 12,124 3,073 - - - - -
Total Sources $ 66,519 $ 332 $ 12,413 $ 53,774 $ - $ - $ - $ - $ -
Operation and Maintenance Impact: (1,000s)
Personnel - - - - -
Contractual Services - - - - -
Supplies - - - - -
Utilities - - - - -
Insurance - - - - -
Total O&M Impact $ - $ - $ - $ - $ -
Total Revenue $ - $ - $ - $ - $ -
49
"""##
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