I've been trying to write a macro to find all the CAPITALIZED words in a text.
This is my code :
args1(10).Value = "[:space:][:upper:][:alpha:]+[:space:]|[:space:][:upper:][:alpha:]+[:print:]|\<[:upper:][:alpha:]+[:space:]"
It works perfectly.
HOWEVER, it doesn't work if I add this to it : args1(10).Value = "[:space:][:upper:][:alpha:]+[:space:]|[:space:][:upper:][:alpha:]+[:print:]|\<[:upper:][:alpha:]+[:space:]|[^John|^Mary]" — I want to find all the capitalized words EXCEPT "John" and "Mary" (the text I'm working with has those names ad nauseum and they clutter my search so I want to exclude them — but my script doesn't work).
Can anybody please help me?
Thank you so much!
[Solved] Regular expression: capitalized words EXCEPT some
-
- Posts: 3
- Joined: Mon Sep 06, 2021 2:04 pm
[Solved] Regular expression: capitalized words EXCEPT some
Last edited by Hagar Delest on Mon Sep 06, 2021 8:06 pm, edited 2 times in total.
Reason: Tagged [Solved].
Reason: Tagged [Solved].
OpenOffice 4.1.10 on Windows 10
Re: Trying to write a macro
args1(10).Value = "[:space:][:upper:][:alpha:]+[:space:]|[:space:][:upper:][:alpha:]+[:print:]|\<[:upper:][:alpha:]+[:space:]|[^John|^Mary]"
As a first thought, each " | " represents OR but the final " | " needs to be AND giving "(any capitalised word) AND NOT (John OR Mary). Or should John be JOHN?
Or do a workaround hack. First convert all John to J*** and all Mary to M***. Now search. Now convert them back.
As a first thought, each " | " represents OR but the final " | " needs to be AND giving "(any capitalised word) AND NOT (John OR Mary). Or should John be JOHN?
Or do a workaround hack. First convert all John to J*** and all Mary to M***. Now search. Now convert them back.
LO 6.4.4.2, Windows 10 Home 64 bit
See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.
Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.
Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Re: Trying to write a macro
The following regular expression seems to work in the standard Find & Replace dialog.
Code: Select all
(?!\bJohn|\bMary)\b[:upper:][:alpha:]*
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
-
- Posts: 3
- Joined: Mon Sep 06, 2021 2:04 pm
Re: Trying to write a macro
Do you mean : args1(10).Value = "[:space:][:upper:][:alpha:]+[:space:]|[:space:][:upper:][:alpha:]+[:print:]|\<[:upper:][:alpha:]+[:space:] AND NOT [John] OR Mary" — is that what you mean? I've just tried that and it doesn't seem to be working.
OpenOffice 4.1.10 on Windows 10
-
- Posts: 3
- Joined: Mon Sep 06, 2021 2:04 pm
Re: Trying to write a macro
Replying to FJCC : Wow, you've solved it for me! Much simpler code than mine, too! THANK YOU SO MUCH! BTW, do you mind telling me what the exclamation mark in your code means? (I haven't seen come across that yet in the haphazard study I've been doing). Once again, thank you!
David
David
OpenOffice 4.1.10 on Windows 10
Re: Trying to write a macro
The ((?! ...) is a negative look ahead assertion. It looks ahead of the current cursor position and returns TRUE if the text encountered does not match the text in the parentheses. It is part of a family of such operators that look forward or backward and are either positive or negative. You can read about them in the Regular Expression Operators section here.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.