pycharmers.cli.regexp_replacement module

pycharmers.cli.regexp_replacement.regexp_replacement(argv=['-M', 'html', '.', '_build'])[source]

String replacement in a file using regular expression

  • .json path can be specified by “json-dir / json-file” or “json-path

  • output file path can be specified by “output-path” or “input-path + suffix

Parameters
  • -I/--input-path (str) – Path/to/input file.

  • -O/--output-path (str) – Path/to/output file.

  • -jd/--json-dir (str) – Path/to/json directory.

  • -jf/--json-file (str) – File name in json-dir.

  • -jp/--json-path (str) – Path/to/json file.

  • -suf/--suffix (str) – Suffix of output filename.

  • -ext/--extension (str) – When ‘input-path’ is directory, only file in ‘input-path’ with this extension will be replaced.

  • --show-all (bool) – If True, show all json file descriptions in json-dir

  • --show (bool) – If True, show the content of a specified json file.

  • --quiet (bool) – Whether to make the output quiet.

Note

When you run from the command line, execute as follows:

$ regexp_replacement -I sample.md -jf sample.json
$ regexp_replacement --show-all
$ regexp_replacement -jf sample.json --show

Examples

  • Replace Input file using regular expression.
    $ regexp-replacement -I sample.md -jf sample.json
        Json   file : /Users/iwasakishuto/.pycharmers/cli/regexp_replacement/labbooks.json
        Input  file : sample.md
        Output file : sample.md
    $ regexp-replacement -I sample.md -jf sample.json -suf suffix
        Json: /Users/iwasakishuto/.pycharmers/cli/regexp_replacement/labbooks.json
        Input path : sample.md
        Output path: sample_suffix.md
    
  • Show all json file in json-dir

    $ regexp-replacement --show-all
    Json directory: /Users/iwasakishuto/.pycharmers/cli/regexp_replacement
    * sample.json: Sample Json
    
  • Show the content of the file at json-path

    $ regexp-replacement -jf sample.json --show
    Json:  /Users/iwasakishuto/.pycharmers/cli/regexp_replacement/sample.json
    {
        "description" : "Sample Json",
        "patterns" : [
            ["`(.*?)`", "<span class="code">\1</span>"],
            ["+(.*?)+", "<span class="strong">\1</span>"]
        ]
    }