{"id":15432930,"url":"https://github.com/simonw/datasette-rure","last_synced_at":"2025-04-19T17:50:28.276Z","repository":{"id":47367835,"uuid":"207630174","full_name":"simonw/datasette-rure","owner":"simonw","description":"Datasette plugin that adds a custom SQL function for executing matches using the Rust regular expression engine","archived":false,"fork":false,"pushed_at":"2019-09-11T22:59:38.000Z","size":19,"stargazers_count":5,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-18T07:53:28.653Z","etag":null,"topics":["datasette","datasette-io","datasette-plugin","regular-expressions","sqlite"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-10T18:09:33.000Z","updated_at":"2022-05-01T00:48:10.000Z","dependencies_parsed_at":"2022-08-03T04:45:53.796Z","dependency_job_id":null,"html_url":"https://github.com/simonw/datasette-rure","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/simonw%2Fdatasette-rure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fdatasette-rure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fdatasette-rure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fdatasette-rure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonw","download_url":"https://codeload.github.com/simonw/datasette-rure/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249752994,"owners_count":21320644,"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":["datasette","datasette-io","datasette-plugin","regular-expressions","sqlite"],"created_at":"2024-10-01T18:29:25.269Z","updated_at":"2025-04-19T17:50:28.220Z","avatar_url":"https://github.com/simonw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# datasette-rure\n\n[![PyPI](https://img.shields.io/pypi/v/datasette-rure.svg)](https://pypi.org/project/datasette-rure/)\n[![CircleCI](https://circleci.com/gh/simonw/datasette-rure.svg?style=svg)](https://circleci.com/gh/simonw/datasette-rure)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/datasette-rure/blob/master/LICENSE)\n\nDatasette plugin that adds a custom SQL function for executing matches using the Rust regular expression engine\n\nInstall this plugin in the same environment as Datasette to enable the `regexp()` SQL function.\n\n    $ pip install datasette-rure\n\nThe plugin is built on top of the [rure-python](https://github.com/davidblewett/rure-python) library by David Blewett.\n\n## regexp() to test regular expressions\n\nYou can test if a value matches a regular expression like this:\n\n    select regexp('hi.*there', 'hi there')\n    -- returns 1\n    select regexp('not.*there', 'hi there')\n    -- returns 0\n\nYou can also use SQLite's custom syntax to run matches:\n\n    select 'hi there' REGEXP 'hi.*there'\n    -- returns 1\n\nThis means you can select rows based on regular expression matches - for example, to select every article where the title begins with an E or an F:\n\n    select * from articles where title REGEXP '^[EF]'\n\nTry this out: [REGEXP interactive demo](https://datasette-rure-demo.datasette.io/24ways?sql=select+*+from+articles+where+title+REGEXP+%27%5E%5BEF%5D%27)\n\n## regexp_match() to extract groups\n\nYou can extract captured subsets of a pattern using `regexp_match()`.\n\n    select regexp_match('.*( and .*)', title) as n from articles where n is not null\n    -- Returns the ' and X' component of any matching titles, e.g.\n    --     and Recognition\n    --     and Transitions Their Place\n    -- etc\n\nThis will return the first parenthesis match when called with two arguments. You can call it with three arguments to indicate which match you would like to extract:\n\n    select regexp_match('.*(and)(.*)', title, 2) as n from articles where n is not null\n\nThe function will return `null` for invalid inputs e.g. a pattern without capture groups.\n\nTry this out: [regexp_match() interactive demo](https://datasette-rure-demo.datasette.io/24ways?sql=select+%27WHY+%27+%7C%7C+regexp_match%28%27Why+%28.*%29%27%2C+title%29+as+t+from+articles+where+t+is+not+null)\n\n## regexp_matches() to extract multiple matches at once\n\nThe `regexp_matches()` function can be used to extract multiple patterns from a single string. The result is returned as a JSON array, which can then be further processed using SQLite's [JSON functions](https://www.sqlite.org/json1.html).\n\nThe first argument is a regular expression with named capture groups. The second argument is the string to be matched.\n\n    select regexp_matches(\n        'hello (?P\u003cname\u003e\\w+) the (?P\u003cspecies\u003e\\w+)',\n        'hello bob the dog, hello maggie the cat, hello tarquin the otter'\n    )\n\nThis will return a list of JSON objects, each one representing the named captures from the original regular expression:\n\n    [\n        {\"name\": \"bob\", \"species\": \"dog\"},\n        {\"name\": \"maggie\", \"species\": \"cat\"},\n        {\"name\": \"tarquin\", \"species\": \"otter\"}\n    ]\n\nTry this out: [regexp_matches() interactive demo](https://datasette-rure-demo.datasette.io/24ways?sql=select+regexp_matches%28%0D%0A++++%27hello+%28%3FP%3Cname%3E%5Cw%2B%29+the+%28%3FP%3Cspecies%3E%5Cw%2B%29%27%2C%0D%0A++++%27hello+bob+the+dog%2C+hello+maggie+the+cat%2C+hello+tarquin+the+otter%27%0D%0A%29)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fdatasette-rure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonw%2Fdatasette-rure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fdatasette-rure/lists"}