{"id":15066829,"url":"https://github.com/amogil/url_regex","last_synced_at":"2025-04-10T13:53:27.159Z","repository":{"id":53019453,"uuid":"63502397","full_name":"amogil/url_regex","owner":"amogil","description":"Provides the best regex for validating or extracting URLs","archived":false,"fork":false,"pushed_at":"2021-04-09T11:34:28.000Z","size":32,"stargazers_count":10,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-21T02:08:05.905Z","etag":null,"topics":["extract-urls","parsing","regexes","ruby","ruby-gem","rubygem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amogil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-16T21:10:00.000Z","updated_at":"2024-01-25T15:56:16.000Z","dependencies_parsed_at":"2022-08-23T21:50:23.854Z","dependency_job_id":null,"html_url":"https://github.com/amogil/url_regex","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amogil%2Furl_regex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amogil%2Furl_regex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amogil%2Furl_regex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amogil%2Furl_regex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amogil","download_url":"https://codeload.github.com/amogil/url_regex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248229079,"owners_count":21068820,"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":["extract-urls","parsing","regexes","ruby","ruby-gem","rubygem"],"created_at":"2024-09-25T01:12:50.489Z","updated_at":"2025-04-10T13:53:27.142Z","avatar_url":"https://github.com/amogil.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/amogil/url_regex.svg?branch=master)](https://travis-ci.org/amogil/url_regex)\n[![Code Climate](https://codeclimate.com/github/amogil/url_regex/badges/gpa.svg)](https://codeclimate.com/github/amogil/url_regex)\n[![Gem Version](https://badge.fury.io/rb/url_regex.svg)](https://badge.fury.io/rb/url_regex)\n\n# UrlRegex\n\nProvides the best known regex for validating and extracting URLs.\nIt builds on amazing work done by [Diego Perini](https://gist.github.com/dperini/729294)\nand [Mathias Bynens](https://mathiasbynens.be/demo/url-regex).\n\nWhy do we need a gem for this regex?\n\n- You don't need to follow changes and improvements of original regex.\n- You can slightly customize the regex: a scheme can be optional, and you can get the regex for validation or parsing.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'url_regex'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install url_regex\n\n## Usage\n\nGet the regex:\n\n    UrlRegex.get(options)\n\nwhere options are:\n\n- `scheme_required` indicates that schema is required, defaults to `true`.\n\n- `mode` can gets either `:validation`, `:parsing` or `:javascript`, defaults to `:validation`.\n\n`:validation` asks to return the regex for validation, namely, with `\\A` prefix, and with `\\z` postfix.\nThat means, it matches whole text:\n\n    UrlRegex.get(mode: :validation).match('https://www.google.com').nil?\n    # =\u003e false\n    UrlRegex.get(mode: :validation).match('link: https://www.google.com').nil?\n    # =\u003e true\n\n`:parsing` asks to return the regex for parsing:\n\n    str = 'links: google.com https://google.com?t=1'\n    str.scan(UrlRegex.get(mode: :parsing))\n    # =\u003e [\"https://google.com?t=1\"]\n\n    # schema is not required\n    str.scan(UrlRegex.get(scheme_required: false, mode: :parsing))\n    # =\u003e [\"google.com\", \"https://google.com?t=1\"]\n\n`:javascript` asks to return the regex formatted for use in Javascript files or as `pattern` attribute values on HTML inputs. For this purpose, you'd use the `source` method on the Regexp object instance in order to produce a string that Javascript will understand. These examples make use of the Rails `text_field` method to generate HTML input elements.\n\n    regex = UrlRegex.get(mode: :javascript)\n    text_field(:site, :url, pattern: regex.source)\n    # =\u003e \u003cinput type=\"text\" id=\"site_url\" name=\"site[url]\" pattern=\"[javascript URL regex]\" /\u003e\n\n    regex = UrlRegex.get(scheme_required: false, mode: :javascript)\n    text_field(:site, :url, pattern: regex.source)\n    # =\u003e \u003cinput type=\"text\" id=\"site_url\" name=\"site[url]\" pattern=\"[javascript URL regex with optional scheme]\" /\u003e\n\n`UrlRegex.get` returns regular Ruby's [Regex](http://ruby-doc.org/core-2.0.0/Regexp.html) object,\nso you can use it as usual.\n\nAll regexes are case-insensitive.\n\n## FAQ\n\nQ: Hey, I want to parse HTML, but it doesn't work:\n\n    str = '\u003ca href=\"http://google.com?t=1\"\u003eLink\u003c/a\u003e'\n    str.scan(UrlRegex.get(mode: :parsing))\n    # =\u003e \"http://google.com?t=1\"\u003eLink\u003c/a\u003e\"\n\nA: Well, you probably know that parsing HTML with regex is\n[a bad idea](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags).\nIt requires matching corresponding open and close brackets, that makes the regex even more complicated.\n\nQ: How can I speed up processing?\n\nA: Generated regex depends only on options, so you can get the regex only once and cache it.\n\n## Contributing\n\n1. Fork it ( https://github.com/[my-github-username]/url_regex/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famogil%2Furl_regex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famogil%2Furl_regex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famogil%2Furl_regex/lists"}