首页 > 解决方案 > 需要在 Notepad++ 中使用 REGEX 来查找包含空格的行中字符的长度

问题描述

我有一个 TEXT 文件,其中有 4700 行 30 个字符的值。数字字符位于 1 到 8 的位置,之后应该只有空格。我在 NOTEPAD++ 中使用 REGEX 来查找 2 个不同的场景:

  1. 我想查找在我的文本文件的任何行上是否存在位置 1-8 中小于 6 的字符长度。
  2. 我的文本文件中是否有长度 > 30 的行。我想我找到了答案,但想要一些确认,因为我没有在我的结果中找到任何东西。这是我在 NOTEPAD++ 中使用的找到这些值:.{30, }

任何帮助/方向将不胜感激。谢谢。

这是我的文件的示例:

332268-1                      
322335                        
322375                        
322393                        
322368-1                      
322381                        
322475                        
323912-1                      
322539                        
322641                        
322641                        
322514-1                      
322638                        
322978                        
322978                        
322638-1                      
287686                        
287735                        
322579                        
322643                        
323113                        
323257                        
331875                        
331875                        
322637-1                      
322720-1                      
322745-1                      
322679                        
322702                        
322971                        
324548                        
322971                        
333146-1                      

标签: regexnotepad++

解决方案


1号将是^\d{0,5}\s+\n

 ^ matches the beginning of the string or line
 \d digit
 {0,5} matches quantify or proceeding token
 \s whitespace
 + quantifier matches 1 or more
 \n is a new line

2号将是^.{31,}

 ^ matches the beginning of the string or line
 . matches any character but line breaks
 {31,} matches any line that is 31 characters or greater.

推荐阅读