import Foundation
let pattern = #"(.*)(?<=,)((.\n|.)*)(\D\d{6}\D)"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = ##"""
Rotex Group
Manufacturing Units
Rotex Automation Limited (Unit 1)
987/11, GIDC Estate
Makarpura,sfg
Vadodara-390010.
987/11, GIDC Estate
Makarpura,sfg
manipoor, gujratpunjab,
Vadodara-390010.
Gujarat, India.
Ph :
asf aSD ASFAdf aSD ASd asd asd aSDAdasd
1606-1609, 16th Floor, Rupa Solitaire, Plot No
A-1, Sector 1, Millennium Business Park, Mahape, Navi Mumbai - 400710
szdgfads
#257, GK complex, Amarjyothi, BHCS layout,
Inner Ring Road,Domlur 548998
gh,xfzgdxfzg,
Bangalore-560071.
asdgasdg asdg
adgzs
2-5, First Flr., Samarpan Complex, S.P.Ring Rd Ambli-Bopal Crossing,
Ahmedabad -380058
This is a simple expression to check a US street address entered on either one or two lines. Being short it does not check that the road qualifer is "valid" (eg. drive, avenue, etc), but it does allow for the extended zip code. A word of warning, the multiline mode can be picky about ending the first line with extra space.
asdf
210/211, Richmond Towers, 12, Richmond Road, Bangalore, Karnataka - 560025
sadfasf
Your E-Mail :
Brief Message
Submit Clear
KHETAN MARBLE
Jyoti,Minerals Pvt, Ltd 456345
Green Marble House Pvt. Ltd.
Administrative Office:
8-D, New Fatehpura,
Rajasthan, India 456456
Tel.: +91-294-2560062, 2560443
Fax: +91-294-2560677
Corporate Office:
509-A, International Trade Tower,Nehru Place,
New Delhi-111019, India
Tel.: +91-11-26216877, 26434303
Fax: +91-11-26448005
Email: info@khetanmarbles.com
Website : www.khetanmarbles.com
"""##
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