简体   繁体   中英

Regex to avoid all words between {{ and }}

I am using https://github.com/tbroadley/spellchecker-cli .

I have a JSON file that I'd like to run spellChecker on and it looks like this:

{
  "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.

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 .

So, make sure your JSON looks like

{
  "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:

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

In *nix, Perl is preferable:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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