Get In Touch
This form does not yet contain any fields.

    « Dismiss iPhone keyboard | Main | The Best Question is the One Never Asked »

    Regular Expressions on iOS - NSRegularExpression

    Regular Expressions are a vital part of most developer's toolkits and can be incredibly useful when processing text strings.  Apple recently introduced regular expressions at WWDC 2010 for iOS 4.0 as the framework NSRegularExpression.  I've recently started working with this framework for a project that does some web scraping and created some functions that I think would be useful to most iOS devs.

    This first example will take in a string and will return the first match it finds to the specific regular expression syntax, in this example that expression will find all http URLs.  

    The second example will take a regex pattern, find it in the given string and substitute all matches for that pattern creating a new string when done.  The sample function below will find all whitespace and substitute it for '&'.

    Reader Comments (1)

    Thanks a lot for this great piece of code, that helped me a LOT!

    March 6, 2012 | Unregistered CommenterWinston

    PostPost a New Comment

    Enter your information below to add a new comment.

    My response is on my own website »
    Author Email (optional):
    Author URL (optional):
    Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>