import Foundation
let pattern = #"Order Total:\nCDN\$ ([\d\.]+)"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = ##"""
---------- Forwarded message ----------
From: auto-confirm@amazon.ca <auto-confirm@amazon.ca>
Date: Fri, Nov 6, 2015 at 11:24 AM
Subject: Your Amazon.ca order of "Cheetah Mounts ALAMLB..."
To: Charles Regan <charles.regan@gmail.com>
Amazon.ca
Your Orders
| Your Account | Amazon.ca
Order Confirmation
Order #701-7756830-8577864
Hello Charles Regan,
Thank you for shopping with us. We’ll send a confirmation once your item has shipped. Your order details are indicated below. If you would like to view the status of your order or make any changes to it, please visit Your Orders on Amazon.ca.
Your estimated delivery date is:
Wednesday, November 18, 2015
Your shipping speed:
FREE Shipping
Your Orders
Your order will be sent to:
CHARLES REGAN
1419 CH. DE L'ETANG-DU-NORD
ETANG-DU-NORD, Québec G4T3B9
Canada
Order Details
Order #701-7756830-8577864
Placed on Friday, November 6, 2015
Cheetah Mounts ALAMLB Articulating Arm (20" Extension) TV Wall Mount Bracket for 23-49 inch LCD, LED and Plasma Flat Screen TVs up to VESA 400x400 and 66lbs, with full Ballhead Tilt, Swivel, and Rotation Motion, Including a Twisted Veins 10' Braided High Speed with Ethernet HDMI Cable and a 6" 3-Axis Magnetic Bubble Level
Electronics
Sold by SPN Imports and Services
Condition: New
Facebook
Twitter
Pinterest
CDN$ 29.33
Item Subtotal:
CDN$ 29.33
Shipping & Handling:
CDN$ 0.00
Estimated Tax (GST/HST):
CDN$ 0.00
Estimated Tax (PST/QST):
CDN$ 0.00
Order Total:
CDN$ 29.33
To learn more about ordering, go to Ordering from Amazon.ca.
If you want more information or need more assistance, go to Help.
We hope to see you again soon!
Amazon.ca
This email was sent from a notification-only address that cannot accept incoming email. Please do not reply to this message.
Amazon.ca
Vos commandes
| Votre compte | Amazon.ca
Confirmation de la commande
Commande n° 701-7756830-8577864
Bonjour Charles Regan,
Merci d'avoir magasiné chez nous. Nous vous enverrons une confirmation une fois que votre article aura été expédié. Les détails de votre commande sont indiqués ci-dessous. Veuillez visiter la section Vos commandes sur Amazon.ca si vous souhaitez voir le statut de votre commande ou apporter des modifications à celle-ci.
Votre date de livraison prévue est le :
mercredi 18 novembre 2015
Votre mode de livraison :
Livraison GRATUITE
Your Orders
Votre commande sera expédiée à :
CHARLES REGAN
1419 CH. DE L'ETANG-DU-NORD
ETANG-DU-NORD, Québec G4T3B9
Canada
Détails de la commande
Commande n° 701-7756830-8577864
Passée le vendredi 6 novembre 2015
Cheetah Mounts ALAMLB Articulating Arm (20" Extension) TV Wall Mount Bracket for 23-49 inch LCD, LED and Plasma Flat Screen TVs up to VESA 400x400 and 66lbs, with full Ballhead Tilt, Swivel, and Rotation Motion, Including a Twisted Veins 10' Braided High Speed with Ethernet HDMI Cable and a 6" 3-Axis Magnetic Bubble Level
Electronics
Vendu par SPN Imports and Services
Condition : New
Facebook
Twitter
Pinterest
CDN$ 29.33
Sous-total article(s) :
CDN$ 29.33
Expédition et manutention :
CDN$ 0.00
Estimation de la TPS/TVH :
CDN$ 0.00
Estimation de la TVP/TVQ :
CDN$ 0.00
Total de la commande :
CDN$ 29.33
Pour en apprendre davantage à propos des commandes, consultez la page Commander sur Amazon.ca.
Si vous souhaitez obtenir de plus amples informations ou si vous avez besoin d'assistance, consultez nos pages d'aide.
Nous espérons vous revoir bientôt.
Amazon.ca
Ce courriel a été envoyé à partir d'une adresse de notification uniquement qui ne peut recevoir de courriels entrants. Veuillez ne pas répondre à ce message.
"""##
let stringRange = NSRange(location: 0, length: testString.utf16.count)
if let firstMatch = regex.firstMatch(in: testString, range: stringRange) {
let result: [String] = (1 ..< firstMatch.numberOfRanges).map { (testString as NSString).substring(with: firstMatch.range(at: $0)) }
print(result)
} else {
print("No matches were found.")
}
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