Last active
June 17, 2023 12:43
-
-
Save kraigspear/b7b1e4052f80a4daf06ef5e919925e6d to your computer and use it in GitHub Desktop.
Extract out hashtags using Swift Regex Literals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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