{ "info": { "author": "Krzysztof Dorosz", "author_email": "cypreess@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "Welcome to python-Rex\n=====================\n\n.. image:: https://pypip.in/v/python-rex/badge.png\n :target: https://crate.io/packages/python-rex\n.. image:: https://pypip.in/d/python-rex/badge.png\n :target: https://crate.io/packages/python-rex\n.. image:: https://travis-ci.org/cypreess/python-rex.png?branch=master\n :target: https://travis-ci.org/cypreess/python-rex\n.. image:: https://coveralls.io/repos/cypreess/python-rex/badge.png?branch=master\n :target: https://coveralls.io/r/cypreess/python-rex?branch=master\n \nPython **Rex** is regular expressions for humans. (**Rex** is also abbreviation from **re** **X** tended).\n\n**Rex** is for the `re standard module `_ as\n`requests `_ is for `urllib module `_.\n\n**Rex** also is `latin for \"king\" `_, and the king of regular expressions is Perl.\nSo **Rex** API tries to mimic at least some Perl's idioms.\n\nSupported Python versions: 2.6, 2.7, 3.3\n\nInstallation\n============\n\n::\n\n pip install python-rex\n\nor\n\n::\n \n pip install -e git+https://github.com/cypreess/python-rex.git#egg=rex-dev\n\nThere are no external dependencies. \n\n\n::\n \n from rex import rex\n\n\n\nQuickstart\n==========\n\nDo that::\n\n from rex import rex\n print (\"Your ticket number: XyZ-1047. Have fun!\" == rex(\"/[a-z]{3}-(\\d{4})/i\"))[1]\n \n\ninstead of doing that::\n\n import re\n regex = re.compile(\"[a-z]{3}-(\\d{4})\", flags=re.IGNORECASE)\n m = regex.search(\"Your ticket number: XyZ-1047. Have fun!\")\n \n if m is not None:\n print m.group(1)\n else:\n print None\n \n # or in shorter way\n print m.group(1) if m else None\n\n\n(both should print ``1047``).\n\nDocs\n====\n\nSo far **Rex** supports:\n\n* simple matching (first match),\n* substitution,\n* all python re flags.\n\n\n\nMatching \n--------\n\nThe most obvious usage - test condition by matching to string::\n\n if 'This is a dog' == rex('/dog/'):\n print 'Oh yeah'\n\n\nor::\n\n if 'My lucky 777 number' == rex('/[0-9]+/'):\n print 'Number found'\n\n\nYou can use Perl notation and prepend ``m`` character to your search::\n\n\n if 'My lucky 777 number' == rex('m/[0-9]+/'):\n print 'Number found'\n\n\nbut you can also simply check your match::\n\n\n if ('My lucky 777 number' == rex('m/[0-9]+/'))[0] == '777':\n print 'Number found'\n\nor even groups::\n\n\n if ('My lucky 777 number' == rex('m/(?P[0-9]+)/'))['number'] == '777':\n print 'Number found'\n\n\nRemember a mess with re module when it does not match anything? Rex won't let you down,\nit will kindly return ``None`` for whatever you ask::\n\n >>> print ('My lucky 777 number' == rex('m/(?P[0-9]+)/'))['no_such_group']\n None\n\n >>> print (\"I don't tell you my lucky number\" == rex('m/(?P[0-9]+)/'))['number']\n None\n\n\nSubstituting\n------------\n\nSubstitution can be made by prefixing pattern with ``s`` character (like in perl expression)::\n\n >>> print \"This is a cat\" == rex('s/CAT/dog/i')\n This is a dog\n\n\nFlags\n-----\n\nEvery **Rex** pattern as in Perl patterns allows to suffix some flags, e.g. ``rex('/pattern/iu')`` for enabling ``i`` and ``u`` flag. **Rex** supports all standard python re flags:\n\n* ``d`` - re.DEBUG\n* ``i`` - re.IGNORECASE\n* ``l`` - re.LOCALE\n* ``m`` - re.MULTILINE\n* ``s`` - re.DOTALL\n* ``u`` - re.UNICODE\n* ``x`` - re.VERBOSE\n\nCaching\n-------\n\n**Rex** caches all patterns so reusing patterns is super fast. You can always clear **Rex** cache by calling ``rex_clear_cache()`` or\ndisable caching for specific patterns ``rex('/pattern/', cache=False)``.\n\n\nRex for orthodox\n----------------\n\nIf you are so orthodox pythonist that couldn't leave with overloaded ``==`` operator syntax in your codebase,\nyou can use \"orthodox mode\" of rex. Just put the string to match/substitute against as a second argument::\n\n >>> bool(rex(\"/dog/\", \"This is a dog\"))\n True\n >>> rex(\"s/cat/dog/\", \"This is a cat\")\n 'This is a dog'\n\nAdditionally Rex objects are callable. This is especially useful in situations where you need to process many values\nagainst the same regular expression::\n\n >>> my_re = rex(\"/foo/\")\n >>> for thing in [\"foobar\", \"bar\", \"barfoo\"]:\n ... print bool(my_re(thing))\n True\n False\n True\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/cypreess/python-rex", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "python-rex", "package_url": "https://pypi.org/project/python-rex/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/python-rex/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/cypreess/python-rex" }, "release_url": "https://pypi.org/project/python-rex/0.4/", "requires_dist": null, "requires_python": null, "summary": "Python regular expressions for humans", "version": "0.4" }, "last_serial": 1029175, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "4bc0954daa97db4795d05458dac750a1", "sha256": "3872464fd08763a7ca6d617be55733bab8ef926d3d580b7103bd88ba8418c739" }, "downloads": -1, "filename": "python-rex-0.1.tar.gz", "has_sig": false, "md5_digest": "4bc0954daa97db4795d05458dac750a1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 489, "upload_time": "2013-06-25T22:43:39", "url": "https://files.pythonhosted.org/packages/e1/4f/04a5c5f7cacffbf273981486476f7336349620888d864dbe2cfc252c898f/python-rex-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "207ae0d77463ccfb31c0fdd53fcdce79", "sha256": "e272e53807d171e9b05d768c775c68932b77aea6480561e6c6f92b9283d0d9c3" }, "downloads": -1, "filename": "python-rex-0.1.1.tar.gz", "has_sig": false, "md5_digest": "207ae0d77463ccfb31c0fdd53fcdce79", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1469, "upload_time": "2013-06-26T07:11:23", "url": "https://files.pythonhosted.org/packages/2d/2f/93c570c0ce1f502dab17b0425fd45240035a597e1f5e85a995963cad0de6/python-rex-0.1.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "8ebbf9b158a42bdc313643dc634b493a", "sha256": "a40b0e641667bd3571c8dc6f803ad2b4af3843339752bbdc04cc6aa0c2f2fae1" }, "downloads": -1, "filename": "python-rex-0.2.tar.gz", "has_sig": false, "md5_digest": "8ebbf9b158a42bdc313643dc634b493a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1563, "upload_time": "2013-06-27T05:43:12", "url": "https://files.pythonhosted.org/packages/5e/67/a3ef09a07660d80a30463cf76ab9054d2078448a215fb049959d092421c0/python-rex-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "efeb065c6e36d5cd6167269442223952", "sha256": "709354ad525faad280f96f738973289dd0d17ccbcb63d46a5554f8db8b718738" }, "downloads": -1, "filename": "python-rex-0.3.tar.gz", "has_sig": false, "md5_digest": "efeb065c6e36d5cd6167269442223952", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1775, "upload_time": "2013-07-07T22:33:06", "url": "https://files.pythonhosted.org/packages/87/9e/c010f793e408a66f38cf064ea98f9cb2562a0653df248e65adffafb39507/python-rex-0.3.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "8aa4ad8fc980398e15dd1d7f9eb0c586", "sha256": "e05a2a741cb6176103a732a9db1f998fb6390e7f37f57e7f8beec88de4336c36" }, "downloads": -1, "filename": "python-rex-0.3.1.tar.gz", "has_sig": false, "md5_digest": "8aa4ad8fc980398e15dd1d7f9eb0c586", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3420, "upload_time": "2013-07-09T12:25:15", "url": "https://files.pythonhosted.org/packages/7d/9d/c804553ffdf58dc8ddedae7823f1128776e4c72e27752c1724671a5559f2/python-rex-0.3.1.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "381ad5596284a9b276a6f25f351d5f21", "sha256": "7649e2b6d15132971bc46ba67993845712b879ca797459972428b35c5ec79592" }, "downloads": -1, "filename": "python-rex-0.4.tar.gz", "has_sig": false, "md5_digest": "381ad5596284a9b276a6f25f351d5f21", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3675, "upload_time": "2014-03-14T07:27:09", "url": "https://files.pythonhosted.org/packages/0a/b0/72eeada9b37285b80f745e596c3e678e35be690712d66f2a7152787852fe/python-rex-0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "381ad5596284a9b276a6f25f351d5f21", "sha256": "7649e2b6d15132971bc46ba67993845712b879ca797459972428b35c5ec79592" }, "downloads": -1, "filename": "python-rex-0.4.tar.gz", "has_sig": false, "md5_digest": "381ad5596284a9b276a6f25f351d5f21", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3675, "upload_time": "2014-03-14T07:27:09", "url": "https://files.pythonhosted.org/packages/0a/b0/72eeada9b37285b80f745e596c3e678e35be690712d66f2a7152787852fe/python-rex-0.4.tar.gz" } ] }