All Projects → fjcaetano → Nsstringmask

fjcaetano / Nsstringmask

Licence: mit
NSStringMask allows you to apply masks or formats to NSStrings using NSRegularExpression to input your format.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Nsstringmask

Tfmask
Terraform utility to mask select output from `terraform plan` and `terraform apply`
Stars: ✭ 148 (-38.84%)
Mutual labels:  regex, mask
Placeholdifier
Turn any website into a live wireframe
Stars: ✭ 230 (-4.96%)
Mutual labels:  mask
Lolcate Rs
Lolcate -- A comically fast way of indexing and querying your filesystem. Replaces locate / mlocate / updatedb. Written in Rust.
Stars: ✭ 191 (-21.07%)
Mutual labels:  regex
Stringi
THE String Processing Package for R (with ICU)
Stars: ✭ 204 (-15.7%)
Mutual labels:  regex
Fancy Regex
Rust library for regular expressions using "fancy" features like look-around and backreferences
Stars: ✭ 199 (-17.77%)
Mutual labels:  regex
Rainbow
🌈 Colorize commands output or STDIN using patterns.
Stars: ✭ 217 (-10.33%)
Mutual labels:  regex
Awesome Devtools
🤖 A curated list of in-browser bookmarklets, tools, and resources for modern full-stack software engineers.
Stars: ✭ 184 (-23.97%)
Mutual labels:  regex
Autolinktextviewv2
AutoLinkTextView is a TextView that supports automatic detection of Hashtags (#), Mentions (@) , URLs (http://), Phone Nubers and emails
Stars: ✭ 238 (-1.65%)
Mutual labels:  regex
Flutter Masked Text
A masked text for Flutter.
Stars: ✭ 229 (-5.37%)
Mutual labels:  mask
Ros people object detection tensorflow
An extensive ROS toolbox for object detection & tracking and face/action recognition with 2D and 3D support which makes your Robot understand the environment
Stars: ✭ 202 (-16.53%)
Mutual labels:  mask
Regex Automata
A low level regular expression library that uses deterministic finite automata.
Stars: ✭ 203 (-16.12%)
Mutual labels:  regex
Regexpu
A source code transpiler that enables the use of ES2015 Unicode regular expressions in ES5.
Stars: ✭ 201 (-16.94%)
Mutual labels:  regex
Tj
stdin line timestamps. single binary, no dependencies. osx & linux & windows. plays well with jq.
Stars: ✭ 218 (-9.92%)
Mutual labels:  regex
Common Regex
🎃 常用正则表达式 - 收集一些在平时项目开发中经常用到的正则表达式。
Stars: ✭ 2,488 (+928.1%)
Mutual labels:  regex
Grab
experimental and very fast implementation of a grep
Stars: ✭ 230 (-4.96%)
Mutual labels:  regex
Maskededittext
It allows you to add a mask to EditText
Stars: ✭ 184 (-23.97%)
Mutual labels:  mask
Retina
A regex-based programming language.
Stars: ✭ 202 (-16.53%)
Mutual labels:  regex
Learn gnugrep ripgrep
Example based guide to mastering GNU grep and ripgrep
Stars: ✭ 204 (-15.7%)
Mutual labels:  regex
Regex For Regular Folk
🔍💪 Regular Expressions for Regular Folk — A visual, example-based introduction to RegEx [BETA]
Stars: ✭ 242 (+0%)
Mutual labels:  regex
Swaglyrics For Spotify
📃 Get lyrics of currently playing Spotify song so you don't sing along with the wrong ones and embarrass yourself later. Very fast.
Stars: ✭ 235 (-2.89%)
Mutual labels:  regex

NSStringMask

CI Status Version License Platform codecov Carthage compatible


This tiny library was developed to help you apply masks and formats to strings.

For instance, suppose you have the string 12345678 and want to format it as a Social Security Number (which regex pattern is \d{3}-\d{2}-\d{3}). With NSStringMask, all you have to do is [NSStringMask maskString:@"12345678" withPattern:@"(\\d{3})-(\\d{2})-(\\d{3})"] and the result will be "123-45-678". Simple enough?

Installation

You can clone the repository and copy the folder Classes to your project or install it via cocoa pods.

pod "NSStringMask"

References

Take a look on the complete documentation >.

Please, note that this is still in development and may be unstable. Suggestions and improvements are always welcome, specially with tests that are not my greatest skill.

I'll try to keep the branch master with the most stable updates, even before deploying new features.

I've also created this gist with some commonly used patterns. Feel free to improve it!

Usage Example

Whenever you set a string pattern or a regex, it must have at least one capturing parentheses [group]. This is because the class comprehends that everything that is in between parentheses are the strings that must be matched and replaced. If you need explicit parentheses in your format, escape it with slashes:

[NSStringMask maskString:@"c" withPattern:@"\\w"]
// result: nil

[NSStringMask maskString:@"c" withPattern:@"(\\w)"]
// result: "c"

[NSStringMask maskString:@"3" withPattern:@"\\((\\d)\\)"]
// result: (3)

[NSStringMask maskString:@"3" withPattern:@"\\((\\d{4})\\)" placeholder:@"_"]
// result: (3___)

These are few of the many forms to use NSStringMask:

Simple Pattern

In this case, the method will return the expected result only if the provided string's length is equal or longer than expected:

[NSStringMask maskString:@"1234567890" withPattern:@"(\\d{3})-(\\d{3})-(\\d{4})"]
// result: 123-456-7890

If the string is shorter, the method won't apply the format, but instead, return a cleaned string with the valid characters:

[NSStringMask maskString:@"123foo456" withPattern:@"(\\d{3})#(\\d{4})]
// result: 123456

Pattern with Placeholder:

Placeholders allow you to fill strings shorter than expected with characters to complete the formatting:

[NSStringMask maskString:@"" withPattern:@"(\\d{2})/(\\d{2})/(\\d{4})" placeholder:@"_"]
// result: __/__/____

It can also be a long string. In this case, the replacement will restart for each group in your pattern:

[NSStringMask maskString:@"" withPattern:@"(\\d{2})/(\\d{2})/(\\d{4})" placeholder:@"abcde"]
// result: ab/ab/abcd

NSRegularExpression

You may also provide an instance of NSRegularExpression instead of a pattern, the result is the same.

When a pattern is passed, the class creates a NSRegularExpression object with 0 option. If you need it to be different, it may be interesting to provide the regex and not a string pattern.

UITextFieldMask

To create a text field with a mask, just set it as an instance UITextFieldMask in your class or nib (if using the Interface Builder). It’s recommended that the mask is passed in the initialization of the text field, so if the text field is in a nib, the mask must be passed inside [UIViewController viewDidLoad] or [UIView awakeFromNib].

Help Wanted

Do you love NSStringMask and work actively on apps that use it? We'd love if you could help us keep improving it! Feel free to message us or to start contributing right away!

Complete Documentation >

License

NSStringMask is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].