{"id":16959496,"url":"https://github.com/crdoconnor/simex","last_synced_at":"2025-06-13T09:40:06.188Z","repository":{"id":57467217,"uuid":"65320727","full_name":"crdoconnor/simex","owner":"crdoconnor","description":"Ultra-simple human readable DSL for matching text.","archived":false,"fork":false,"pushed_at":"2017-02-05T20:51:49.000Z","size":30,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T14:04:54.110Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","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/crdoconnor.png","metadata":{"files":{"readme":"README.rst","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-08-09T19:01:15.000Z","updated_at":"2024-10-27T12:29:56.000Z","dependencies_parsed_at":"2022-09-10T02:01:46.061Z","dependency_job_id":null,"html_url":"https://github.com/crdoconnor/simex","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crdoconnor%2Fsimex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crdoconnor%2Fsimex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crdoconnor%2Fsimex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crdoconnor%2Fsimex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crdoconnor","download_url":"https://codeload.github.com/crdoconnor/simex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065281,"owners_count":21041872,"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":[],"created_at":"2024-10-13T22:45:07.743Z","updated_at":"2025-04-11T22:10:33.502Z","avatar_url":"https://github.com/crdoconnor.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"SimEx\n=====\n\nSimEx is a tool that lets you write simple, readable equivalents of regular expressions that\ncompile down to regular expressions.\n\nThis is useful for:\n\n* Improving the readability and maintainability of code that uses long regexes with a lot of escaped characters.\n* Allowing non-developers to read and understand simple regex-equivalents and potentially even write their own.\n\nSimex is *not* a full replacement for regular expressions and its use is not suitable everywhere a regex is used.\n\nIt is ideally used where you usually want to compare two strings but you occasionally need to compare two\nstrings with a pattern embedded within them.\n\nIt is an embodiment of `the rule of least power \u003chttps://en.wikipedia.org/wiki/Rule_of_least_power\u003e`_.\n\nTo install::\n\n  $ pip install simex\n\n\nExample\n-------\n\n.. code-block:: python\n\n  \u003e\u003e\u003e from simex import Simex\n  \u003e\u003e\u003e simex = Simex({\"url\": r\".*?\", \"anything\": r\".*?\"})\n  \u003e\u003e\u003e regex = simex.compile(\"\"\"\u003ca href=\"{{ url }}\"\u003e{{ anything }}\u003c/a\u003e\"\"\")\n  \u003e\u003e\u003e regex.match(\"\"\"\u003ca href=\"http://www.cnn.com\"\u003eCNN\u003c/a\u003e\"\"\") is not None\n  True\n\n\nDo I have to define all of the sub-regular expressions myself?\n--------------------------------------------------------------\n\nNo. SimEx also contains a built in library of commonly used regular expressions.\n\nThis will also work:\n\n.. code-block:: python\n\n  \u003e\u003e\u003e from simex import Simex\n  \u003e\u003e\u003e my_simex = DefaultSimex()\n  \u003e\u003e\u003e regex = my_simex.compile(\"\"\"\u003ca href=\"{{ url }}\"\u003e{{ anything }}\u003c/a\u003e\"\"\")\n  \u003e\u003e\u003e regex\n  re.compile(r'\\\u003ca\\ href\\=\\\"(ht|f)tp(s?)\\:\\/\\/[0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\.\\?\\,\\\\'\\/\\\\\\+\u0026amp;%\\$#_]*)?\\\"\\\u003e.*?\\\u003c\\/a\\\u003e', re.UNICODE)\n\n  \u003e\u003e\u003e regex.match(\"\"\"\u003ca href=\"http://www.cnn.com\"\u003eCNN\u003c/a\u003e\"\"\") is not None\n\nAll regexes in the existing library can be overridden, and more can be added, e.g.\n\n.. code-block:: python\n\n  \u003e\u003e\u003e simex = DefaultSimex({\"url\": r\".*?\", \"mycode\": r\"[A-Z][0-9][0-9][0-9]\"})\n\nCurrently there are five in the list of pre-defined regexes:\n\n* URL\n* Email\n* Integer\n* Number\n* Anything\n\nPull requests with commonly required non-controversial regexes are welcome.\n\n\nUsing {{ and }} creates conflicts for me! Why not [[[ and ]]]?\n--------------------------------------------------------------\n\n{{ and }} have a special meaning in some languages which you may want to use\nwith simex - e.g. jinja2.\n\nIn order to prevent confusion in such circumstances, you can define your\nown delimeters:\n\n.. code-block:: python\n\n  \u003e\u003e\u003e from simex import Simex\n  \u003e\u003e\u003e simex = Simex(open_delimeter=\"[[[\", close_delimeter=\"]]]\")\n  \u003e\u003e\u003e simex.compile(\"\"\"\u003ca href=\"[[[ url \"\u003e[[[ anything ]]]\u003c/a\u003e\"\"\")\n  \u003e\u003e\u003e simex.match(\"\"\"\u003ca href=\"http://www.cnn.com\"\u003eCNN\u003c/a\u003e\"\"\") is not None\n\n\nMatching exact strings\n----------------------\n\nBy default a simex will not match an exact string. i.e. it will produce:\n\n.. code-block:: python\n\n  \u003e\u003e\u003e from simex import Simex\n  \u003e\u003e\u003e simex = Simex({\"url\": r\".*?\", \"anything\": r\".*?\"})\n  \u003e\u003e\u003e regex = simex.compile(\"\"\"\u003ca href=\"{{ url }}\"\u003e{{ anything }}\u003c/a\u003e\"\"\")\n  \u003e\u003e\u003e regex\n  re.compile(r'\\\u003ca\\ href\\=\\\".*?\\\"\\\u003e.*?\\\u003c\\/a\\\u003e', re.UNICODE)\n  \u003e\u003e\u003e regex.match(\"\"\"\u003ca href=\"http://www.cnn.com\"\u003eCNN\u003c/a\u003e THERE IS MORE TEXT\"\"\") is not None\n  True\n\nHowever, if you want, simexes can be used to do exact matching. For example:\n\n.. code-block:: python\n\n  \u003e\u003e\u003e from simex import Simex\n  \u003e\u003e\u003e simex = Simex({\"url\": r\".*?\", \"anything\": r\".*?\"}, exact=True)\n  \u003e\u003e\u003e regex = simex.compile(\"\"\"\u003ca href=\"{{ url }}\"\u003e{{ anything }}\u003c/a\u003e\"\"\")\n  \u003e\u003e\u003e regex\n  re.compile(r'^\\\u003ca\\ href\\=\\\".*?\\\"\\\u003e.*?\\\u003c\\/a\\\u003e$', re.UNICODE)\n  \u003e\u003e\u003e regex.match(\"\"\"\u003ca href=\"http://www.cnn.com\"\u003eCNN\u003c/a\u003e\"\"\") is not None\n  True\n  \u003e\u003e\u003e regex.match(\"\"\"\u003ca href=\"http://www.cnn.com\"\u003eCNN\u003c/a\u003e THERE IS MORE TEXT\"\"\") is not None\n  False\n\nMatching can also treat whitespace (tabs, spaces and newlines) as interchangeable. For example:\n\n.. code-block:: python\n\n  \u003e\u003e\u003e from simex import Simex\n  \u003e\u003e\u003e simex = Simex({\"url\": r\".*?\", \"anything\": r\".*?\"}, flexible_whitespace=True)\n  \u003e\u003e\u003e regex = simex.compile(\"\"\"\u003ca href=\"{{ url }}\"\u003e{{ anything }}\u003c/a\u003e\"\"\")\n  \u003e\u003e\u003e regex\n  re.compile(r'\\\u003ca\\\\s+href\\=\\\".*?\\\"\\\u003e.*?\\\u003c\\/a\\\u003e', re.UNICODE)\n  \u003e\u003e\u003e regex.match(\"\"\"\u003ca   href=\"http://www.cnn.com\"\u003eCNN\u003c/a\u003e\"\"\") is not None\n  True\n\n.. code-block:: python\n\n\n\nHow does it work?\n-----------------\n\nThe regular expression simply escapes an entire simexpression, except for the\ncomponents surrounded by {{ and }}, which it replaces with defined regular\nexpressions - like \"email\" or \"anything\" or \"number\" defined in the dict.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrdoconnor%2Fsimex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrdoconnor%2Fsimex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrdoconnor%2Fsimex/lists"}