import Foundation
let pattern = #"(\.amenity_icon\..*)"|<h4>(.*)<\/h4>|<p>(.*)<\/p>"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
function LoadTooltips() {
$(".units_table .amenity_icon.icon_climate").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Temperature Controlled</h4><p>Units are heated and/or cooled. See manager for details.</p></div>"
}
});
$(".units_table .amenity_icon.icon_secure").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Secure Units</h4><p>Units protected with advanced security features.</p></div>"
}
});
$(".units_table .amenity_icon.icon_driveup").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Drive-up Access</h4><p>Plenty of room to park your vehicle in front of your storage unit.</p></div>"
}
});
$(".units_table .amenity_icon.icon_wine").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Wine Storage</h4><p>Specialty space with temperature control for wines.</p></div>"
}
});
$(".units_table .amenity_icon.icon_vehicle").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>RV, Car, Boat Parking</h4><p>Larger parking spaces for grown-up toys (indoors or outdoors).</p></div>"
}
});
$(".units_table .amenity_icon.icon_mobile").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Portable Storage</h4><p>We bring the unit to you and then store it at our secure location.</p></div>"
}
});
$(".units_table .amenity_icon.icon_twentyfour").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>24 Hour Access</h4><p>Units are accessible 24 hours a day.</p></div>"
}
});
$(".units_table .amenity_icon.icon_elevator").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Elevator Access</h4><p>Reduce heavy lifting and easily access your storage unit with our elevator.</p></div>"
}
});
$(".units_table .amenity_icon.icon_interior").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Interior Storage</h4><p>Indoor units provide added protection against weather and theft.</p></div>"
}
});
$(".units_table .amenity_icon.icon_ramp").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Ramp</h4><p>Ramps make it easy to maneuver dollies – which means less lifting for you!</p></div>"
}
});
$(".units_table .amenity_icon.icon_covered_parking").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Covered Parking</h4><p>Need protection from the elements? Check out our covered parking.</p></div>"
}
});
$(".units_table .amenity_icon.icon_uncovered_parking").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Uncovered Parking</h4><p>The most affordable option for parking your vehicle at our secure location.</p></div>"
}
});
$(".units_table .amenity_icon.icon_ground_floor").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Ground Floor</h4><p>Reduce your heavy lifting by taking advantage of our ground level units.</p></div>"
}
});
$(".units_table .amenity_icon.icon_upstairs").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Upstairs</h4><p>Looking to save money? Try our upstairs units for added savings.</p></div>"
}
});
$(".units_table .amenity_icon.icon_conference").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Conference Room</h4><p>Need a conference room for important client meetings? Take advantage of ours.</p></div>"
}
});
$(".units_table .amenity_icon.icon_fenced").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Fenced & Gated</h4><p>Perimeter fencing and gate entry give your unit 360 degree protection.</p></div>"
}
});
$(".units_table .amenity_icon.icon_kiosk").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>24 Hour Kiosk</h4><p>Rent storage units, make payments and more with our convenient 24 hour kiosk.</p></div>"
}
});
$(".units_table .amenity_icon.icon_resident").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Resident Manager</h4><p>Our resident manager lives onsite for added security and customer service.</p></div>"
}
});
$(".units_table .amenity_icon.icon_dollies").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Dollies/Handcarts</h4><p>Loading and unloading is easy with our complimentary handcarts & dollies.</p></div>"
}
});
$(".units_table .amenity_icon.icon_shipping").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Shipping Services</h4><p>Skip the long lines at the post office and ship your packages at our facility!</p></div>"
}
});
$(".units_table .amenity_icon.icon_callcenter").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Call Center</h4><p>Through our call center, you can reserve your unit when it's convenient for you.</p></div>"
}
});
$(".units_table .amenity_icon.icon_camera").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Security Cameras</h4><p>Fenced or gated area with recorded video surveillance.</p></div>"
}
});
$(".units_table .amenity_icon.icon_power").tooltip({
track: false,
delay: 0,
showURL: false,
left: -126,
top: -100,
bodyHandler: function () {
return "<div class=\"sidebar_tooltip\"><h4>Power</h4><p>Electrical outlets within or near your unit.</p></div>"
}
});
}
"""#
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