Skip to content

Instantly share code, notes, and snippets.

@kraigspear
Last active June 17, 2023 12:43
Show Gist options
  • Save kraigspear/b7b1e4052f80a4daf06ef5e919925e6d to your computer and use it in GitHub Desktop.
Save kraigspear/b7b1e4052f80a4daf06ef5e919925e6d to your computer and use it in GitHub Desktop.
Extract out hashtags using Swift Regex Literals
let hashTagExpression = /(#+[a-zA-Z0-9(_)]{1,})/
let note = "this is my #note with a #tag #whatup"
let ranges = note.ranges(of: regEx2)
ranges.forEach {
// Remove the # by skipping over the first character.
let newStart = note.index(after: $0.lowerBound)
let newRange = newStart..<$0.upperBound
let str = String(note[newRange])
print(str)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment