GREP: Find lines more than 12 characters excluding spaces

瘦欲@ 提交于 2019-12-24 07:38:24

问题


I am using a GREP search in Sublime Text 3. I want to find all lines that are more than 12 characters, excluding spaces.

Example

Mac and Cheese
Peanut Butter and Jelly Sandwich

In the above example, Mac and Cheese would not be found, because it's exactly 12 characters excluding spaces.

How would I do this?

I can use the following to find all lines that are more than 12 characters. But I am not sure how to exclude spaces:

(?<=.{13}).+

回答1:


The pattern (?<=.{13}).+ will assert what is on the left is 13 characters and the dot will also match a space. Then it will match any char except a whitespace 1+ times.

You could match horizontal whitespace chars and repeat 13 or more times matching a non whitespace char for example \S (or specify what you would allow to match) followed by 0+ horizontal whitespace chars.

^\h*(?:\S\h*){13,}$
  • ^ Start of string
  • \h* Match 0+ times a horizontal whitespace char
  • (?: Non capturing group
    • \S\h* Match non whitespace char, then 0+ horizontal whitespace chars
  • ){13,} Close group and repeat 13+ times
  • $ End of string

Regex demo



来源:https://stackoverflow.com/questions/57628730/grep-find-lines-more-than-12-characters-excluding-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!