How to indicate the option key

I am trying to use the macro https://forum.keyboardmaestro.com/uploads/default/original/3X/a/a/aa52b6281a6eb67675774b828567bdd7bc870d3f.jpeg
Instead of [|n\r\s] I want to scrub pharagraph. What are the symbols to do that? I found that Option 7 is the key combination for a paragraph mark (Pilcrow). Maybe if I knew how to indicate the option key, I could use this scrub KM


This is the context:

I'm not entirely sure what you mean by "scrub paragraph," but I believe you want to remove line breaks, carriage returns, and leading spaces to merge paragraphs into one continuous block of text.

You can achieve this with a search and replace operation. Here's a regex pattern that should work:

Remove line-feed (newline) characters and whitespace before each paragraph.kmmacros (4.3 KB)

image

This pattern will:

  • Remove new line characters
  • Strip "Horizontal White Space character" from the beginning of paragraphs
  • Replace them with a single pipe marker (to show where paragraphs were separated). You can replace it with a space or other character.

For more complex text processing needs, I'd recommend familiarizing yourself with regex tools and testing patterns before applying them to your actual content. You can find an explanation of the regex I used previously here:

Important: In Keyboard Maestro, make sure to add (?m) at the beginning of your search pattern if you're working with multi-line text.

I hesitated to reply to him because I don't know what he wants either. Merging lines separated by newlines into single paragraphs is an extremely difficult thing to do since you sometimes need to understand the meaning of the words to know if a new paragraph is intended there or not.

For example, if a line ends with "Mrs." then it's probably intended to be joined by the next line as part of the same sentence. But you actually have to understand the text to know that. There is no regex that understands the meaning of sentences.

Yes, It would be much easier to create better regex patterns if we had sample texts to test them on.

2 Likes

Here is sample text which contains extra pharagraph signs:
influenced much by drugs, though Ergot (both by mouth and hypodermically),

Hydrastis, Liquor Ferri Perchloridi, Potassium Bromide, Hazeline, Arsenic, and Thyroid

Gland were tried. During the last two periods, however, Calcium Chloride in scruple

doses, three times a day seemed to have a good effect, but this might have been due

to the natural close of menstruation. Frequent plugging of the vagina, sometimes

I tried to add in the characters that @JuanWayri suggested, but I don't know how to use the macro that someone else made. I have text with too many pharagraph marks. I copy it as the 1 clipboard.

I think I do not understand the process of implimenting the macro.

Here is what I cobbled together with little understanding of the use process.
Scrub - paragraph signs.kmmacros (3.4 KB)

The regex pattern I recommended works correctly with your text:

SEARCH FOR: (?m)^\h*(\V*)\R*

REPLACE WITH: $1%Space%

Note: The pattern used in your original macro was slightly different, visually similar, but using different characters.

I’ve updated your macro to include the correct version. If you import it, be sure to disable the previous one to avoid conflicts.

Scrub - paragraph signs (modified).kmmacros (3.3 KB)

For a detailed explanation and live testing, you can use this Regex101 link:

Don't confuse the pilcrow that programs like MS Word use to show the end of a paragraph with the character you get when you hit your Return key.

If you do want to search and/or replace pilcrows, simply use ⌥7 to insert the character in the text field:

Pilcrow Replace Demo.kmmacros (3.0 KB)

Image

If you want to remove "empty" paragraphs, the simplest way is to replace every "two or more Returns" with a single linefeed -- it's good to think of it in that way because your source text may indicate new lines (your "paragraphs") with a \n linefeed (the modern Mac way), a \r return (the old Mac way), or even \r\n (Windows). Luckily the regex \R covers all of those, so to remove empty paragraphs while keeping the to the same new-line type:

image

Of course, you may want to convert the Returns so they are always Mac linefeeds, removing empty paragraphs at the same time:

image

As you can see, there's lots of ways to do this depending on exactly what you want to do. It helps if you provide samples of the "before" and "after" text so we're all aiming at the same goal -- use the Forum's "Preformatted text" option:
image|98x9275%

...to help prevent confusing display issues.