{ "info": { "author": "Simon Willison", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": "# 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\\w+) the (?P\\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\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/simonw/datasette-rure", "keywords": "", "license": "Apache License, Version 2.0", "maintainer": "", "maintainer_email": "", "name": "datasette-rure", "package_url": "https://pypi.org/project/datasette-rure/", "platform": "", "project_url": "https://pypi.org/project/datasette-rure/", "project_urls": { "Homepage": "https://github.com/simonw/datasette-rure" }, "release_url": "https://pypi.org/project/datasette-rure/0.3/", "requires_dist": [ "datasette", "rure", "pytest ; extra == 'test'" ], "requires_python": "", "summary": "Datasette plugin that adds a custom SQL function for executing matches using the Rust regular expression engine", "version": "0.3" }, "last_serial": 5817359, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "62f26c1582a730b90e52bd73b57f0f9e", "sha256": "a08f5fe80d7cb1cde664802c37c03e5149d8aafe5345150a22fe880926312294" }, "downloads": -1, "filename": "datasette_rure-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "62f26c1582a730b90e52bd73b57f0f9e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6210, "upload_time": "2019-09-10T18:18:07", "url": "https://files.pythonhosted.org/packages/5f/74/4d3a092e543e0f094e5fafe24f501d4e89b9abf7595dbd54368a808e7e42/datasette_rure-0.1-py3-none-any.whl" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "54c4f8d0771c85f9db28a759d8adc1af", "sha256": "1f08230ced83fbcd5f83954f8cc76c9d41cd6164c7f5d47498263992dd5803f7" }, "downloads": -1, "filename": "datasette_rure-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "54c4f8d0771c85f9db28a759d8adc1af", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7162, "upload_time": "2019-09-11T03:25:29", "url": "https://files.pythonhosted.org/packages/5d/39/90cc8828a3fcd6ee96ab8f28f1248d3306555d9ff9ac003b943c2cc82418/datasette_rure-0.2-py3-none-any.whl" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "052971b4c1f769be61995469d83cce6c", "sha256": "19405f0891a3efdbfa8ac6964606ce9d5fd6c38f6fe2f50509381b95a4924a97" }, "downloads": -1, "filename": "datasette_rure-0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "052971b4c1f769be61995469d83cce6c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7484, "upload_time": "2019-09-11T23:00:09", "url": "https://files.pythonhosted.org/packages/95/a9/191f77fb0e11767e25f797cb87c62b3c84b79ce12f278f45bb014e88dc18/datasette_rure-0.3-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "052971b4c1f769be61995469d83cce6c", "sha256": "19405f0891a3efdbfa8ac6964606ce9d5fd6c38f6fe2f50509381b95a4924a97" }, "downloads": -1, "filename": "datasette_rure-0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "052971b4c1f769be61995469d83cce6c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7484, "upload_time": "2019-09-11T23:00:09", "url": "https://files.pythonhosted.org/packages/95/a9/191f77fb0e11767e25f797cb87c62b3c84b79ce12f278f45bb014e88dc18/datasette_rure-0.3-py3-none-any.whl" } ] }