user4634316
user4634316

Reputation:

Notepad++ regexp, find capital letters but ignore certain words

I would like to find all capital letters, but I need to ignore certain words/letters

For example: I'm Surprised. I, Myself I Am Excited.

In this case here, I'm trying to mark all capitals but exclude the 2 lone I and I'm.


This is my starting point: [A-Z]?(I), but it only finds words containing I.


EDIT:
Another thing came up. I will also need to exclude the first capital letter after a period ., question mark ? or exclamation mark !, but not if it is 3 dots ...
And if the word after those is starting with a lowercase, it will have to be marked as well.
Also, there could be other junk in between (like numbers or other punctuation such as : or ,).

Example: - I'm surprised. - Myself I am excited. 846 3:34,343535 Said "Where..." No... 846 3:34,343535 Not... not interested. - PUT. what is it? "It's gone" 846 3:34,343535 Tonight.

In this case, I need to mark the capitals of Where, No, Not, PUT and Tonight. As well as the lowercase not and what (since those are coming after a . ! or ?).
Again, there could be some other junk in between the period and the next word like " or '
Expected output: image

Upvotes: 4

Views: 5612

Answers (3)

ArtBindu
ArtBindu

Reputation: 1972

I am quite confused about your requirement. It's not clear and the output image throwing 404 error.

I am trying to resolve your problem please verify:

txt = `- I'm surprised.
- Myself I am excited.
846 3:34,343535
Said "Where..."
No... 
846 3:34,343535
Not... not interested. - PUT. what is it?
"It's gone"
846 3:34,343535
Tonight.`

Solution-01: (with case validation)

regex: /[A-Z]+\w*[\.\!\?]+/g
txt.match(/[A-Z]+\w*[\.\!\?]+/g)
['Where...', 'No...', 'Not...', 'PUT.', 'Tonight.']

enter image description here

Solution-02: (without case validation)

regex: /[A-Z]+\w*[\.\!\?]+/gi
txt.match(/[A-Z]+\w*[\.\!\?]+/gi)
['surprised.', 'excited.', 'Where...', 'No...', 'Not...', 'interested.', 'PUT.', 'it?', 'Tonight.']

enter image description here

Upvotes: 0

Just Me
Just Me

Reputation: 1053

@Toto just gave me an alternative answer ( If I want to find only the words that starts with a capital letter):

Use the following:

  • Ctrl+H

  • Find what: \b[A-Z]\w+

  • CHECK Match case

  • CHECK Wrap around

  • CHECK Regular expression

  • UNCHECK . matches newline

  • Replace all


Upvotes: -1

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626748

You may use

(?!\bI\b)[A-Z]

Make sure Match case is enabled! Else, use (?-i)(?!\bI\b)[A-Z].

The negative lookahead will fail all cases of I where it is a whole word.

Also, pay special attention to the Match case option - it should be ON.

enter image description here

Upvotes: 2

Related Questions