正则表达式仅选择特定数量的空格

Ahm*_*'ed 4 notepad++ regex

我正在使用记事本++,我想做一个查找和替换操作。
例如

  • 4 个空格表示 1 个制表符
  • 6 个空格表示 2 个制表符等。

在我的文件中,所有空格都在每一行的开头。

我应该使用什么正则表达式来查找确切的空格数?
我想用制表符替换空格(如基于 4 个空格或 6 个空格的单或双制表符)

注意:该文件是一个分类文件,其中说明 4 个空格是父级,6 个空格是子级,8 个空格是子级的子级。

文件示例:

Agriculture, forestry and fishing
 Crop and animal production, hunting and related service activities
   Growing of non perennial crops
     Growing of cereals (except rice), leguminous crops and oil seeds
     Growing of rice
     Growing of vegetables and melons, roots and tubers
Run Code Online (Sandbox Code Playgroud)

Pra*_*nna 9

正则表达式找出行首空格数的语法是

 ^(space_character){number_of_spaces_to_be_found}
.
例如,下面的正则表达式会找到 4 个空格
 ^ {4}
.
在替换框中使用
“\t”
用一个标签替换你的发现。
对于两个选项卡使用
"\t\t"
.