Swiftpack.co - Package - ArtSabintsev/Guitar

Guitar 🎸

A Cross-Platform String and Regular Expression Library written in Swift.

Build Status

Swift Support Documentation Platform

CocoaPods Carthage Compatible SwiftPM Compatible


This library seeks to add common string manipulation functions, including common regular expression capabilities, that are needed in both mobile and server-side development, but are missing in Swift's Standard Library.

The full documentation can be found at http://www.sabintsev.com/Guitar/.

Guitar is also part of Swift's Source Compatibility Suite.


  • [x] Boolean Functions (isAlpha, isNumeric, isUppercase, etc.)
  • [x] Case Functions (camelCased, pascalCased, kebabCased, etc.)
  • [x] Latinization Functions (.latinized(), .withoutAccents())
  • [x] Padding Functions (padLeft, padRight, pad)
  • [x] Regular Expressions (with Common Patterns Built-in)


A small set of functions offered by Guitar were removed in v0.3.0 of the library as Apple added many of these features to the Swift 4 language (aka, Sherlocking). The functions that were removed were: first, last, length, prefixed, suffixed, trimLeft, trimRight, truncated. The reversed function was renamed to reversedString as it acts slightly differently than Swift's built-in reversed function.

Installation Instructions

| Swift Version | Branch Name | Will Continue to Receive Updates? | ------------- | ------------- | ------------- | 5.1 | master | Yes | 5.0 | swift5.0 | No | 4.2 | swift4.2 | No | 4.1 | swift4.1 | No | 3.2 | swift3.2 | No | 3.1 | swift3.1 | No


pod 'Guitar' # Swift 5.1
pod 'Guitar', :git => 'https://github.com/ArtSabintsev/Guitar.git', :branch => 'swift5.0' # Swift 5.0
pod 'Guitar', :git => 'https://github.com/ArtSabintsev/Guitar.git', :branch => 'swift4.2' # Swift 4.2
pod 'Guitar', :git => 'https://github.com/ArtSabintsev/Guitar.git', :branch => 'swift4.1' # Swift 4.1
pod 'Guitar', :git => 'https://github.com/ArtSabintsev/Guitar.git', :branch => 'swift3.2' # Swift 3.2
pod 'Guitar', :git => 'https://github.com/ArtSabintsev/Guitar.git', :branch => 'swift3.1' # Swift 3.1


github "ArtSabintsev/Guitar" // Swift 5.1
github "ArtSabintsev/Guitar" "swift5.0" // Swift 5.0
github "ArtSabintsev/Guitar" "swift4.1" // Swift 4.2
github "ArtSabintsev/Guitar" "swift4.1" // Swift 4.1
github "ArtSabintsev/Guitar" "swift3.2" // Swift 3.2
github "ArtSabintsev/Guitar" "swift3.1" // Swift 3.1

Swift Package Manager

.Package(url: "https://github.com/ArtSabintsev/Guitar.git", majorVersion: 1)

Usage Examples

Regular Expression

  • Guitar makes it easier to use Regular Expressions to test and evaluate String objects.
  • Guitar.Chord enumerates common regular expressions and they are located in GuitarChord.swift.
  • GuitarCommon.swift contains a list of convenience methods for common regular expression evaluations and tests, such as checking the string to determine if it's a valid email address.


Guitar(pattern: String) // A custom regular expression with which to initialize Guitar.

Guitar(chord: Guitar.Chord) // A common regular expression with which to initialize Guitar.


evaluateForRanges(::) returns an array of ranges, [Range<String.Index>], that match a specific regular expression.

Guitar(chord: .firstCharacter).evaluateForRanges(from: "Hello world") // [Range(Swift.String.CharacterView.Index(_base: Swift.String.UnicodeScalarView.Index(_position: 0), _countUTF16: 1)..<Swift.String.CharacterView.Index(_base: Swift.String.UnicodeScalarView.Index(_position: 1), _countUTF16: 1)), Range(Swift.String.CharacterView.Index(_base: Swift.String.UnicodeScalarView.Index(_position: 6), _countUTF16: 1)..<Swift.String.CharacterView.Index(_base: Swift.String.UnicodeScalarView.Index(_position: 7), _countUTF16: 1))]

evaluateForStrings(::) returns an array of strings, [String], that match a specific regular expression.

Guitar(chord: .firstCharacter).evaluateForStrings(from: "Hello world") // ["H", "w"]

test(::) evaluates a string with a specific regular expression. true is returned if matches are found in the string. Otherwise, false is returned.

Guitar(chord: .email).test(string: "hello@world.com") // `true`

String Extension

This library also adds dozens of methods via String extensions that are missing in the Swift Standard Library or not easily accessible on the String class. Examples of each new method can be found in the jazzy-powered documentation.

More specific examples can be found in the tests folder.


Created and maintained by

Arthur Ariel Sabintsev


Stars: 622
Help us keep the lights on


Used By

Total: 1


1.1.0 - Sep 15, 2019

This release adds support for Swift 5.1, iOS 13, and Xcode 11. Full updates here: #26

1.0.2 - Aug 13, 2019

I fixed the Package.swift so that it is now compatible with Xcode 11 and the latest Swift Package Manifest file (// swift-tools-version:4.0).

1.0.1 - Apr 6, 2019

Added #available(iOS 10.0, macOS 10.11, tvOS 10.0, watchOS 3.0, *) back to:

  • func latinized() -> String
  • func withoutAccents() -> String

1.0.0 - Mar 31, 2019

This library has worked as-is for 2 years. Therefore, I am promoting this library to v1.0.0! 🍾

  • Updated for Swift 5
  • Drops iOS-9/tvOS-9 Support
  • #23: evaluateForRanges now supports UTF-16 encoded strings by default (thanks to @cjsliuj)

0.5.0 - Sep 17, 2018

As of Guitar v0.5.0, , all future changes on master will be done in Xcode 10 using Swift 4.2.

For those using Swift v4.1.0, please check out the swift4.1 branch or version 0.4.1 - both point to the same commit hash.