{"id":1860,"url":"https://github.com/brynbellomy/Regex","last_synced_at":"2025-08-02T05:32:56.532Z","repository":{"id":27153076,"uuid":"30622256","full_name":"brynbellomy/Regex","owner":"brynbellomy","description":"Regex class for Swift.  Wraps NSRegularExpression.","archived":false,"fork":false,"pushed_at":"2017-07-04T19:08:32.000Z","size":282,"stargazers_count":67,"open_issues_count":5,"forks_count":16,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-29T18:49:51.704Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://brynbellomy.github.io/Regex/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"prakhar1989/awesome-courses","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brynbellomy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-11T00:29:46.000Z","updated_at":"2022-09-14T03:04:02.000Z","dependencies_parsed_at":"2022-09-01T00:02:18.445Z","dependency_job_id":null,"html_url":"https://github.com/brynbellomy/Regex","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brynbellomy%2FRegex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brynbellomy%2FRegex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brynbellomy%2FRegex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brynbellomy%2FRegex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brynbellomy","download_url":"https://codeload.github.com/brynbellomy/Regex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228443644,"owners_count":17920764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:57.497Z","updated_at":"2024-12-06T09:30:27.889Z","avatar_url":"https://github.com/brynbellomy.png","language":"Swift","funding_links":[],"categories":["Regex","Libs"],"sub_categories":["React-Like","Other free courses","Text"],"readme":"\n# Regex.swift\n\n[![Build Status](https://travis-ci.org/brynbellomy/Regex.svg?branch=0.2.1)](https://travis-ci.org/brynbellomy/Regex)\n[![CocoaPods](https://img.shields.io/cocoapods/v/Regex.svg?style=flat)](http://cocoadocs.org/docsets/Regex)\n[![CocoaPods](https://img.shields.io/cocoapods/p/Regex.svg?style=flat)](http://cocoadocs.org/docsets/Regex)\n[![CocoaPods](https://img.shields.io/cocoapods/l/Regex.svg?style=flat)](http://cocoadocs.org/docsets/Regex)\n[![GitHub tag](https://img.shields.io/github/tag/brynbellomy/Regex.svg?style=flat)]()\n\n# install\n\nUse [CocoaPods](https://cocoapods.org/).\n\nAdd to your `Podfile`:\n\n```ruby\npod 'Regex'\n```\n\nAnd then run `pod install` from the shell:\n\n```sh\n$ pod install\n```\n\n\n# usage\n\n### Simple use cases: `String` extension methods\n\n**String.grep()**\n\nThis method is modeled after Javascript's `String.match()`.  It returns a `Regex.MatchResult` object.  The object's `captures` property is an array of `String`s much as one would expect from its Javascript equivalent.\n\n```swift\nlet result = \"Winnie the Pooh\".grep(\"\\\\s+([a-z]+)\\\\s+\")\n\nresult.searchString == \"Winnie the Pooh\"\nresult.captures.count == 2\nresult.captures[0] == \" the \"\nresult.captures[1] == \"the\"\nresult.boolValue == true       // `boolValue` is `true` if there were more than 0 matches\n\n// You can use `grep()` in conditionals because of the `boolValue` property its result exposes\nlet emailAddress = \"bryn\u0026typos.org\"\nif !emailAddress.grep(\"@\") {\n    // that's not an email address!\n}\n```\n\n**String.replaceRegex()**\n\nThis method is modeled after the version of Javascript's `String.replace()` that accepts a Regex parameter.  \n\n```swift\nlet name = \"Winnie the Pooh\"\nlet darkName = name.replaceRegex(\"Winnie the ([a-zA-Z]+)\", with: \"Darth $1\")\n// darkName == \"Darth Pooh\"\n```\n\n\n### Advanced use cases: `Regex` object and operators\n\n**operator =~**\n\nYou can use the `=~` operator to search a `String` (the left operand) for a `Regex` (the right operand).  It's the same as calling `theString.grep(\"the regex pattern\")`, but might be more clear in some cases.  It returns the same `Regex.MatchResult` object as `String.grep()`.\n\n```swift\n\"Winnie the Pooh\" =~ Regex(\"\\\\s+(the)\\\\s+\")  // returns a Regex.MatchResult\n```\n\nQuickly loop over a `Regex`'s captures:\n\n```swift\nfor capture in (\"Winnie the Pooh\" =~ Regex(\"\\\\s+(the)\\\\s+\")).captures {\n    // capture is a String\n}\n```\n\n# Overriden `map()` function for substitution\n\nA more \"functional programming\" way of doing string replacement is possible via an override for `map()`.  In keeping with the overall aim to avoid reinventing a perfectly good wheel (i.e., `NSRegularExpression`), this function simply calls through to `NSRegularExpression.replaceMatchesInString()`.\n\n```swift\nfunc map (regexResult:Regex.MatchResult, replacementTemplate:String) -\u003e String\n```\n\nYou can use it like so:\n\n```swift\nlet stageName = map(\"Winnie the Pooh\" =~ Regex(\"([a-zA-Z]+)\\\\s+(the)(.*)\"), \"$2 $1\")\n// stageName == \"the Winnie\"\n```\n\nOr if you have some functional operators lying around (for example: \u003chttps://github.com/brynbellomy/Funky\u003e), it's a little less wordy:\n\n```swift\n(\"Winnie the Pooh\" =~ Regex(\"([a-zA-Z]+)\\\\s+(the)(.*)\")) |\u003e map‡(\"$2 $1\")\n```\n\n... but you have to be as crazy as me to find that more readable than `\"Winnie\".replaceRegex(_:withString:)`, so no pressure.\n\n\n\n\n# contributors / authors\n\n- bryn austin bellomy (\u003cbryn.bellomy@gmail.com\u003e)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrynbellomy%2FRegex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrynbellomy%2FRegex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrynbellomy%2FRegex/lists"}