{ "info": { "author": "Zac Hatfield-Dodds", "author_email": "zac@hypothesis.works", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", "Programming Language :: JavaScript", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Testing", "Topic :: Text Processing", "Typing :: Typed" ], "description": "# js-regex\n\n*A compatibility layer to use Javascript regular expressions in Python.*\n\nDid you know that regular expressions may vary between programming languages?\nFor example, let's consider the pattern `\"^abc$\"`, which matches the string\n`\"abc\"`. But what about the string `\"abc\\n\"`? It's also matched in Python,\nbut not in Javascript!\n\nThis and other slight differences can be really important for cross-language\nstandards like `jsonschema`, and that's why `js-regex` exists.\n\n## How it works\n\n```python\nimport re\nimport js_regex\n\nre.compile(\"^abc$\").search(\"abc\\n\") # matches, unlike JS\njs_regex.compile(\"^abc$\").search(\"abc\\n\") # does not match\n```\n\nInternally, `js_regex.compile()` replaces JS regex syntax which has a different\nmeaning in Python with whatever *Python* regex syntax has the intended meaning.\n\n**This only works for the `.search()` method** - there is no equivalent to\n`.match()` or `.fullmatch()` for Javascript regular expressions.\n\nWe also check for constructs which are valid in Python but not JS - such as\nnamed capture groups - and raise an explicit error. Constructs which are valid\nin JS but not Python may also raise an error, because we're still using Python's\n`re.compile()` function under the hood!\n\nThe following table is adapted from [this larger version](https://web.archive.org/web/20130830063653/http://www.regular-expressions.info:80/refflavors.html),\nommiting other languages and any rows where JS and Python have the same behaviour.\n\n| Feature | Javascript | Python | Handling\n| --- | --- | --- | ---\n| `\\a` (bell) | no | yes | Converted to JS behaviour\n| `\\ca`-`\\cz` and `\\cA`-`\\cZ` (control characters) | yes | no | Converted to JS behaviour\n| `\\d` for digits, `\\w` for word chars, `\\s` for whitespace | ascii | unicode | Converted to JS behaviour (including `\\D`, `\\W`, `\\S` for negated classes)\n| `$` (end of line/string) | at end | allows trailing `\\n` | Converted to JS behaviour\n| `\\A` (start of string) | no | yes | Explicit error, use `^` instead\n| `\\Z` (end of string) | no | yes | Explicit error, use `$` instead\n| `(?<=text)` (positive lookbehind) | new in ES2018 | yes | Allowed\n| `(?regex)` (Python named capture group) | no | yes | Not detected (yet)\n| `(?P=name)` (Python named backreference) | no | yes | Not detected (yet)\n| `(?regex)` (JS named capture group) | new in ES2018 | no | Error from Python, not translated (yet)\n| `$` (JS named backreference) | new in ES2018 | no | Error from Python, not translated (yet)\n| `(?i)` (case insensitive) | `/i` only | yes | Explicit error, compile with `flags=re.IGNORECASE` instead\n| `(?m)` (`^` and `$` match at line breaks) | `/m` only | yes | Explicit error, compile with `flags=re.MULTILINE` instead\n| `(?s)` (dot matches newlines) | no | yes | Explicit error, compile with `flags=re.DOTALL` instead\n| `(?x)` (free-spacing mode) | no | yes | Explicit error, there is no corresponding mode in Javascript\n| Backreferences non-existent groups are an error | no | yes | Follows Python behaviour\n| Backreferences to failed groups also fail | no | yes | Follows Python behaviour\n| Nested references `\\1` through `\\9` | yes | no | Follows Python behaviour\n\nNote that in many cases Python-only regex features would be treated as part of\nan ordinary pattern by JS regex engines. Currently we raise an explicit error\non such inputs, but may translate them to have the JS behaviour in a future version.\n\n\n## Changelog\n\n#### 1.0.1 - 2019-10-17\n- Allow use of native strings on Python 2. This is not actually valid according\n to the spec, but it's only going to be around for a few months so whatever.\n\n#### 1.0.0 - 2019-10-04\n- Now considered feature-complete and stable, as all constructs recommended\n for `jsonschema` patterns are supported and all Python-side incompatibilities\n are detected.\n- Compiled patterns are now cached on Python 3, exactly as for `re.compile`\n\n#### 0.4.0 - 2019-10-03\n- Now compatible with Python 2.7 and 3.5, until\n [their respective EOL dates](https://devguide.python.org/#status-of-python-branches).\n\n#### 0.3.0 - 2019-09-30\n- Fixed handling of non-trailing `$`, e.g. in `\"^abc$|^def$\"` both are converted\n- Added explicit errors for `re.LOCALE` and `re.VERBOSE` flags, which have no JS equivalent\n- Added explicit checks and errors for use of Python-only regex features\n\n#### 0.2.0 - 2019-09-28\nConvert JS-only syntax to Python equivalent wherever possible.\n\n#### 0.1.0 - 2019-09-28\nInitial release, with project setup and a very basic implementation.\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/Zac-HD/js-regex", "keywords": "python javascript regex compatibility", "license": "MPL 2.0", "maintainer": "", "maintainer_email": "", "name": "js-regex", "package_url": "https://pypi.org/project/js-regex/", "platform": "", "project_url": "https://pypi.org/project/js-regex/", "project_urls": { "Homepage": "https://github.com/Zac-HD/js-regex" }, "release_url": "https://pypi.org/project/js-regex/1.0.1/", "requires_dist": null, "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "summary": "A thin compatibility layer to use Javascript regular expressions in Python", "version": "1.0.1" }, "last_serial": 5988320, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "d632ea65bd28838d2d7417d1fdf063d1", "sha256": "7f82269ab82dd873f4be9973787f7d5d6e7dec41751df838a3b725ef212a20af" }, "downloads": -1, "filename": "js_regex-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "d632ea65bd28838d2d7417d1fdf063d1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 9211, "upload_time": "2019-09-28T07:48:55", "url": "https://files.pythonhosted.org/packages/83/52/e71012a162638cb68508553e45e67b617c6a606f3a724c61159d7b404a7b/js_regex-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fe16f66794954cbeb847f4fb69200cb8", "sha256": "86b8cd0dd966c02db1c92a33308905cd81564d9c8bba1ca3f18c76943e2d829e" }, "downloads": -1, "filename": "js-regex-0.1.0.tar.gz", "has_sig": false, "md5_digest": "fe16f66794954cbeb847f4fb69200cb8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 3530, "upload_time": "2019-09-28T07:48:57", "url": "https://files.pythonhosted.org/packages/9f/34/22266cb3fa00ed905999980c67e503c650803f095961d31a68ac81622a1e/js-regex-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "23776063c391e39455968825de209888", "sha256": "e9ae8fc6e391b97630132a4369dac67ca276b759002e48f74533424905a9af87" }, "downloads": -1, "filename": "js_regex-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "23776063c391e39455968825de209888", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 9786, "upload_time": "2019-09-28T15:08:46", "url": "https://files.pythonhosted.org/packages/29/be/0a1eea07d331f7253db8431de4cc001026212689f3220c3d29c2e4f3a8df/js_regex-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b9f90cc5ea9be9480bc762c9733f633f", "sha256": "bde788377d81b1c90b9711605a0725c611517dadbd054860cb121911cc0cc608" }, "downloads": -1, "filename": "js-regex-0.2.0.tar.gz", "has_sig": false, "md5_digest": "b9f90cc5ea9be9480bc762c9733f633f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 4128, "upload_time": "2019-09-28T15:08:47", "url": "https://files.pythonhosted.org/packages/ca/12/8416a6e316a8d5d32a3544f528ec8744e11cd68d290ab1eea7ad98b2455b/js-regex-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "c42da86d0de1a808cc9d5360d9d99d97", "sha256": "e2d21c560faf47f7002033c7150df91e7e2fc1d97f2f35117a2a2254a53ba719" }, "downloads": -1, "filename": "js_regex-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c42da86d0de1a808cc9d5360d9d99d97", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 11554, "upload_time": "2019-09-30T09:28:25", "url": "https://files.pythonhosted.org/packages/d2/48/f478a2e9eb39111bed50e07537d84d46e0e1649a48c1ef3e0d81d5a846ed/js_regex-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7891acf1d68af11dc638b3690c900735", "sha256": "44a1b0a32bcf0eeb52aa8b11ff9f375252bdf26dd37ae1066660d1cb7eb34363" }, "downloads": -1, "filename": "js-regex-0.3.0.tar.gz", "has_sig": false, "md5_digest": "7891acf1d68af11dc638b3690c900735", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5771, "upload_time": "2019-09-30T09:28:27", "url": "https://files.pythonhosted.org/packages/23/fd/01e6f7573c57ea7a324cb5d838e4edd7f058a2abcebff621416521b1aa46/js-regex-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "2ccd2f3b844c588439fb3438ea902dd8", "sha256": "b6b36ca44a3bce28e7bbef04a5e8b7af0e986cbab64c9af54be75467b3ae6193" }, "downloads": -1, "filename": "js_regex-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "2ccd2f3b844c588439fb3438ea902dd8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "size": 11794, "upload_time": "2019-10-03T07:44:44", "url": "https://files.pythonhosted.org/packages/44/82/38dcf850c621b024e19fa96e99dacd22703e40a4c03b7a15f5d28ae543a2/js_regex-0.4.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9087e257fa8222940f8d69d1cd9ab15d", "sha256": "e3e5d43292085de9ef61c5b266507a61e8459a938295adb231fb4a00844f5ca6" }, "downloads": -1, "filename": "js-regex-0.4.0.tar.gz", "has_sig": false, "md5_digest": "9087e257fa8222940f8d69d1cd9ab15d", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "size": 6026, "upload_time": "2019-10-03T07:44:46", "url": "https://files.pythonhosted.org/packages/69/14/31336477e1ab57f07f1d1d1f0246fc70bc11e0d6c1d66f5698fff26bec05/js-regex-0.4.0.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "528630cce8b39f597503cdba4bce4b28", "sha256": "aee930ccbca4a254e4547c64e5882c71834ba5210ec397b50627c5662b1bf18d" }, "downloads": -1, "filename": "js_regex-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "528630cce8b39f597503cdba4bce4b28", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "size": 12030, "upload_time": "2019-10-04T01:40:48", "url": "https://files.pythonhosted.org/packages/b1/4e/3493c42964a91f5d96f92f30c924421ee3b346d89db5c0fc45d0d8b04788/js_regex-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4dbd3fb199be0282f6c590aff5e28f7e", "sha256": "90bbc2d2b76c2d9b07058e59e089fb175c7eccb8f82f55bea5bdb3515c03ed8d" }, "downloads": -1, "filename": "js-regex-1.0.0.tar.gz", "has_sig": false, "md5_digest": "4dbd3fb199be0282f6c590aff5e28f7e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "size": 6330, "upload_time": "2019-10-04T01:40:49", "url": "https://files.pythonhosted.org/packages/67/e0/3d27ce2c13cf5585f0cd7c811d73d6ff311c84d5301950757462c9e09a7e/js-regex-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "92e209b6aad365de8b24d6a23854ad54", "sha256": "08e4181bba68878bb2b29ff275f734a34ac2a4fed706977365d1aa527273e5a7" }, "downloads": -1, "filename": "js_regex-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "92e209b6aad365de8b24d6a23854ad54", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "size": 12116, "upload_time": "2019-10-17T08:13:54", "url": "https://files.pythonhosted.org/packages/a8/88/e47daf728197d8b06b6e8ba06c8dfbb1d5c409a24769d6575bf1a824dc8a/js_regex-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f38604d1adbd500c90c42599c04ac7e0", "sha256": "de27bbf11b135a9cc7b03fc35f586705e286d6cd4fbbe112eaa577ed1c82a69f" }, "downloads": -1, "filename": "js-regex-1.0.1.tar.gz", "has_sig": false, "md5_digest": "f38604d1adbd500c90c42599c04ac7e0", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "size": 11673, "upload_time": "2019-10-17T08:13:57", "url": "https://files.pythonhosted.org/packages/7f/fa/9d7fed60e855bf970de97f59586d0a45d7498dd27fbed946fa9d7633db94/js-regex-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "92e209b6aad365de8b24d6a23854ad54", "sha256": "08e4181bba68878bb2b29ff275f734a34ac2a4fed706977365d1aa527273e5a7" }, "downloads": -1, "filename": "js_regex-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "92e209b6aad365de8b24d6a23854ad54", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "size": 12116, "upload_time": "2019-10-17T08:13:54", "url": "https://files.pythonhosted.org/packages/a8/88/e47daf728197d8b06b6e8ba06c8dfbb1d5c409a24769d6575bf1a824dc8a/js_regex-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f38604d1adbd500c90c42599c04ac7e0", "sha256": "de27bbf11b135a9cc7b03fc35f586705e286d6cd4fbbe112eaa577ed1c82a69f" }, "downloads": -1, "filename": "js-regex-1.0.1.tar.gz", "has_sig": false, "md5_digest": "f38604d1adbd500c90c42599c04ac7e0", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "size": 11673, "upload_time": "2019-10-17T08:13:57", "url": "https://files.pythonhosted.org/packages/7f/fa/9d7fed60e855bf970de97f59586d0a45d7498dd27fbed946fa9d7633db94/js-regex-1.0.1.tar.gz" } ] }