【问题标题】:Using RegReplace in Sublime Text 3在 Sublime Text 3 中使用 RegReplace
【发布时间】:2019-02-05 15:34:10
【问题描述】:

在 Sublime Text 3 中安装 RegReplace 插件以对文档进行多项更改。按照文档创建搜索和替换规则,但我提出了几个我找不到解决方案的问题。 这些是创建的规则。

{
    "format": "3.0",
    "replacements":
    {

        "cambio_afiliacion":
        {
            "find": "\\affil{([0-9,]*)}",
            "replace": "<sup>\\1</sup>",
            "greedy": true,
            "greedy_scope": true
        },

        "cambio_section":
        {
            "find": "\\section{(.+?)}",
            "replace": "<h3>\\1</h3>",
            "greedy": true,
            "greedy_scope": true
        },

        "cambio_href":
        {
            "find": "\\href{(.+?)}{(.+?)}",
            "replace": "<a href=\"\\1\">\\2</a>",
            "greedy": true,
            "greedy_scope": true
        },

    }
}

这是你创建的在 Default.sublime-keymap 中运行它的快捷方式

{   
        "keys": ["ctrl+alt+j"],
        "command": "reg_replace",
        "args": {
            "replacements": [
                                "cambio_afiliacion",
                                "cambio_href",
                                "cambio_section",
        ],
            "find_only":false,
        }
    },

要编辑的文档文本如下

 \href{google.com}{google.com}

 Ivonne Narváez Zurita\affil{1}*

 \section{Introducción}

当您执行快捷方式时,您只能以这种方式进行更改

\<a href="google.com">google.com</a>

 Ivonne Narváez Zurita\affil{1}*

 \section{Introducción}

应该得到这个结果

<a href="google.com">google.com</a>
Ivonne Narváez Zurita<sup>1</sup>*
<h3>Introducción</h3>

我找不到错误可能出在哪里,它没有执行所有替换,也没有以正确的方式执行它们,如我得到\&lt;a&gt;\href 所示。

【问题讨论】:

    标签: regex sublimetext3


    【解决方案1】:

    由于模式是在设置中的 JSON 字符串中定义的,因此您必须记住正确定义转义。 \\a 将与 \a 相同,这是一个特殊的正则表达式转义。如果你想要一个文字\,你必须逃避转义\\\\a。这是一个额外的间接级别。您必须考虑 JSON 字符串转义、 正则表达式模式转义。这很烦人,但这就是使用 Sublime 设置时的方式。

            "cambio_afiliacion":
            {
                "find": "\\\\affil{([0-9,]*)}",
                "replace": "<sup>\\1</sup>",
                "greedy": true,
                "greedy_scope": true
            },
    
            "cambio_section":
            {
                "find": "\\\\section{(.+?)}",
                "replace": "<h3>\\1</h3>",
                "greedy": true,
                "greedy_scope": true
            },
    
            "cambio_href":
            {
                "find": "\\\\href{(.+?)}{(.+?)}",
                "replace": "<a href=\"\\1\">\\2</a>",
                "greedy": true,
                "greedy_scope": true
            },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-11
      • 2019-05-16
      • 1970-01-01
      • 2015-03-31
      • 2016-04-24
      • 2015-08-19
      • 1970-01-01
      相关资源
      最近更新 更多