Skip to content

Instantly share code, notes, and snippets.

@loucimj
Last active July 26, 2017 12:04
Show Gist options
  • Save loucimj/fcbf40ba9e676150949dde50e5f53a68 to your computer and use it in GitHub Desktop.
Save loucimj/fcbf40ba9e676150949dde50e5f53a68 to your computer and use it in GitHub Desktop.
search for mention with dots in the middle
content//: Playground - noun: a place where people can play
import UIKit
import Foundation
var str = "Hello, @playground.something more"
//(?<=\\s|^|\\b)(?:[-'.%$#&/]\\b|\\b[-'.%$#&/]|[A-Za-z0-9]|\\([A-Za-z0-9]+\\))+(?=\\s|$|\\b)
let range = NSMakeRange(0, str.characters.count)
var regex = try! NSRegularExpression(pattern: "@(?<=\\s|^|\\b)(?:[-'.%$#&/]\\b|\\b[-'.%$#&/]|[A-Za-z0-9]|\\([A-Za-z0-9]+\\))+(?=\\s|$|\\b)", options: .caseInsensitive)
regex.stringByReplacingMatches(in: str, options: [], range: range, withTemplate: "Found ya!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment