3

I want to select all lines of maximum 12 words that end that do not have any punctuation at the end.

Example:

Love's Equal On Earth

In a moving "in" and "out of focus" image, what you see is what you want to believe about yourself.

I love the feeling.

I must confess every day for better feeling

REsTsora is a non-profit website of millions of free books, movies, software, music, websites, and more.

The Output must find:

Love's Equal On Earth
I must confess every day for better feeling

My regex is not too good:

^(.*?)(\w+\s?){1,12}(?!\S|$)

I want to avoid all the punctuation marks at the end of the lines, that is to find those lines of a maximum of 12 words that have nothing after the last word, no punctuation marks, nothing. My regex stops of the line, before the ' punctuation mark.

Destroy666
  • 12,350

4 Answers4

3
  • Ctrl+H
  • Find what: ^(?:(?:\w+\W){13}.+|.*[.!?]|)\R
  • Replace with: LEAVE EMPTY
  • TICK Wrap around
  • SELECT Regular expression
  • UNTICK . matches newline
  • Replace all

Explanation:

^           # beginning of line
    (?:         # non capture group
        (?:         # non capture group
            \w+         # 1 or more word characters
            \W          # non word character
        ){13}       # end group, must appear 13 times
        .+          # 1 or more any character
      |           # OR
        .*          # 0 or more any character
        [.!?]       # a punctuation, you can add all punctuation you want
      |           # OR
                    # EMPTY
    )           # end group
    \R          # any kind of linebreak

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Toto
  • 19,304
1
^(\S+ ?){1,12}(?<!\.)$

Flags: gm

  • ^: start of line (\S+ ?) => \S+ any character that isn't a whitespace, repeated 1 to n times
  • followed by a optional whitespace ?
  • All repeated 1 to 12 times {1,12}
  • (?<!\.)$ : $ end of line not preceded by a . (feel free to put more like ?,!;)

Try it here.

What's interesting in this one is that you can have punctuation between your words, it will check only the last punctuation at line's end.

Destroy666
  • 12,350
ColdK
  • 11
0
  • Ctrl+H
  • Find what: ^(.*?)(\w+\s){1,12}(\w+)\s*$
  • Replace with: (Leave EMpty)
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all
Just Me
  • 874
-1

Not sure if this is optimal, but try the following:

  • Find what: ^(\w+[^\.,\:!\?]){1,12}$
  • Search mode: Regular expression

Note: I have only considered a few punctuation characters (. , , , : , ! and ?).