{"id":17800995,"url":"https://github.com/refi64/rs","last_synced_at":"2025-03-17T10:34:28.394Z","repository":{"id":31078984,"uuid":"34637970","full_name":"refi64/rs","owner":"refi64","description":"An alternative to sed for text substitution will full Perl regexes and much more","archived":false,"fork":false,"pushed_at":"2015-09-29T16:48:48.000Z","size":12144,"stargazers_count":11,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-16T01:41:27.478Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/refi64.png","metadata":{"files":{"readme":"README.rst","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":"2015-04-27T00:33:27.000Z","updated_at":"2023-05-25T05:30:34.000Z","dependencies_parsed_at":"2022-09-09T03:31:41.131Z","dependency_job_id":null,"html_url":"https://github.com/refi64/rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refi64%2Frs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refi64%2Frs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refi64%2Frs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refi64%2Frs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/refi64","download_url":"https://codeload.github.com/refi64/rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243858693,"owners_count":20359400,"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-27T12:33:06.500Z","updated_at":"2025-03-17T10:34:28.369Z","avatar_url":"https://github.com/refi64.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"rs\n==\n\nrs is a project I created for two purposes:\n\n- An alternative to sed that's easier to use for simple tasks\n- Code golf\n\nThe result? A tool with lots of operators and a few fun ways of doing things. Regexes were never this cool. Ever.\n\n`Try it! \u003chttp://kirbyfan64.github.io/rs\u003e`_ The sources for the demo page are at the ``gh-pages`` branch. Feel free to open any issues with the page or rs itself on the `bug tracker \u003chttp://github/kirbyfan64/rs/issues\u003e`_.\n\nInstallation\n************\n\n::\n   \n   python setup.py install\n\nBasics\n******\n\n::\n\n   rs.py [-h] [-g] [-f] [-d\u003cdelim\u003e] \u003cscript or file\u003e\n\nHere's an example usage::\n\n   cat blah | rs.py 'ab/cd'\n\nThat's equivalent to the longer::\n\n   cat blah | sed 's/ab/cd/'\n\nThe default delimiter is ``/``. To change it, use ``-d``::\n\n   cat blah | rs.py -d: 'ab:cd'\n\nIf the delimiter is not preset in the script, the pattern will assumed to be ``^``, and the replacement will be the script::\n\n   echo -e 'a\\nb' | rs.py 'xyz'\n   # outputs:\n   # xyz1\n   # xyz2\n\nThis can be used to prepend whitespace to a file (useful with Stack Overflow submissions or embedding a file in an rST document).\n\nIf the delimiter is present, but the pattern is empty, the pattern wil be ``$``::\n   \n   echo 'abc' | rs.py '/def'\n   # outputs 'abcdef'\n\nPassing ``-g`` will cause rs to print lots and lots of debugging info while reading patterns and expanding the input.\n\nFile scripts\n************\n\nYou can pass ``-f`` to load a file instead::\n\n   echo \"ab/cd\" \u003e script.rsp\n   cat blah | rs.py -f script.rsp\n\nrs scripts end in ``.rsp``.\n\nLines in a script beginning with `\\#` are comments and are ignored.\n\nOperators\n*********\n\nPrefixing a pattern with a ``+`` is the convergence operator; I got the feature from the excellent `Retina \u003chttps://github.com/mbuettner/retina#retina-is-turing-complete\u003e`_. The convergence operator continuously loops and replaces the pattern until no more substitutions are possible.\n\nPrefixing a pattern with ``*`` makes the pattern case-insensitive.\n\nPrefixing a pattern with ``?`` adds a maximum number of substitutions to the pattern. Only up to that many substitutions will be preformed using that pattern on each line. If the maximum number is over 2 digits long, it *must* be surrounded by brackets. Example::\n   \n   echo aaa | rs.py '?1a/b'\n   # outputs 'baa'\n   echo aaaaaaaaaaaa | rs.py '?[11]a/b'\n   # outputs bbbbbbbbbbba\n\nRepetition\n**********\n\nIf you have ``(a)^^(b)``, where ``a`` is some string and ``b`` is an integer, rs will repeat ``a`` ``b`` times. Example::\n\n    (\\d)(.)/(\\2)^^(\\1)\n\nThis will replace ``2Z`` with ``ZZ``, ``3#`` with ``###``, ``9%`` with ``%%%%%%%%%``, etc.\n\nLength\n******\n\nrs will expand ``(^^a)`` to be the length of ``a``. For instance::\n\n    (\\d+)/(^^\\1)\n\nwill replace ``xx`` with ``2``, ``12323`` with ``5``, and so forth.\n\nMacros\n******\n\nAny lines beginning with a double dollar sign (``$$``) will be assumed to be macro definitions. You can define a macro and use it later on in your script via the dollar sign. Example::\n\n    $$a=1\n    $$b=2\n    $a/$b\n\nwill replace a ``1`` with a ``2``.\n\nMatches\n*******\n\nIf the pattern is just a dollar sign `$$`, then the substitution is used as the\npattern, and the result is the number of matches. For example::\n   \n   echo 1a1b1 | rs.py '$/1.' # prints 2, because the pattern 1. matches twice\n\nTODO\n****\n\n- States. Something so that I can create a state using ``$^x`` and jump to it if a pattern matches.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefi64%2Frs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frefi64%2Frs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefi64%2Frs/lists"}