简体   繁体   English

正则表达式避免 {{ 和 }} 之间的所有单词

[英]Regex to avoid all words between {{ and }}

I am using https://github.com/tbroadley/spellchecker-cli .我正在使用https://github.com/tbroadley/spellchecker-cli

I have a JSON file that I'd like to run spellChecker on and it looks like this:我有一个 JSON 文件,我想在它上面运行拼写检查器,它看起来像这样:

{
  "abc.editGroupsMaxLengthError": "Maximum {{charLen}} characters"
}

I would like to know how can all words between {{ and }} be ignored by the spellchecker.我想知道拼写检查器如何忽略{{}}之间的所有单词。

I tried with我试过

[A-Za-z]+}}

as documented here https://github.com/tbroadley/spellchecker-cli#ignore-regexes to ignore regex.如此处所述https://github.com/tbroadley/spellchecker-cli#ignore-regexes忽略正则表达式。

but it doesn't seem to use }} or {{ for some reason.但由于某种原因,它似乎没有使用}}{{

How can this be fixed?如何解决这个问题?

You can wrap your {{...}} substrings with <!-- spellchecker-disable --> / <!-- spellchecker-enable --> tags, see this Github issue .你可以用<!-- spellchecker-disable --> / <!-- spellchecker-enable -->标签包裹你的{{...}}子字符串,参见这个 Github 问题

So, make sure your JSON looks like所以,确保你的 JSON 看起来像

{
  "abc.editGroupsMaxLengthError": "Maximum <!-- spellchecker-disable -->{{charLen}}<!-- spellchecker-enable --> characters"
}

And the result will be结果将是

C:\Users\admin\Documents\1>spellchecker spellchecker -f spellchecker_test.json
Spellchecking 1 file...

spellchecker_test.json: no issues found

To wrap the {{...}} strings in a certain file in Windows you could use PowerShell, eg, for a spellchecker_test.json file:要将{{...}}字符串包装在 Windows 中的某个文件中,您可以使用 PowerShell,例如,用于spellchecker_test.json文件:

powershell -Command "& {(Get-Content spellchecker_test.json -Raw) -replace '(?s){{.*?}}','<!-- spellchecker-disable -->$&<!-- spellchecker-enable -->' | Set-Content spellchecker_test.json}"

In *nix, Perl is preferable:在 *nix 中,最好使用 Perl:

perl -0777 -i -pe 's/\{\{.*?}}/<!-- spellchecker-disable -->$&<!-- spellchecker-enable -->/s' spellchecker_test.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM