Grep to Strip Bullets From Clipboard?

Hi,

I have a macro with an action that strips bullets at the beginning of paragraphs:

Search and Replace System Clipboard Using Regular Expression (all, ignoring case)
Search for “^(•|▪|●|♦|-|–|−|¬|¬)”
Replace with “”

What I don't understand is why this action only removes the FIRST bullet in the clipboard. If my clipboard contains several paragraphs, each one starting with a bullet, only the first one is gone, even though the action specifies “all matches” and not “first match”.

It might have something with regex and my misunderstanding the way the pattern works. I am obviously NOT an expert.

What do I need to do so that, if the clipboard contains SEVERAL paragraphs, each one starting with a bullet, each bullet is removed by this action?

TIA

Pierre

The leading caret ^ is preventing a multi-line search.
You can change your expression to either:
(•|▪|●|♦|-|–|−|¬|¬)
OR
(?m)^(•|▪|●|♦|-|–|−|¬|¬)

The former will also remove bullets that aren't at the beginning of a line.

See the wiki for more details on the latter.

1 Like

Hey Pierre,

It's best for everyone if you can post the simplest possible test-case macro that demonstrates your issue.

Making it easy for people to download, import, and test your work greatly improves the likelihood that you'll get timely and useful assistance.

By default Keyboard Maestro's RegEx does not employ the multline switch, so it treats your text as a single string.

To turn ON multiline use this:

(?m)your-pattern

Take Care,
Chris

(Keyboard Maestro Moderator)

2 Likes

Thanks. I definitely do not want to remove the bullet chars within the lines, hence my use of ^.

I tried with (?m), but it doesn't seem to work at all. I get zero match, i.e. the action no longer strips even the first bullet.

For instance, I have a clipboard containing this:

•technicien d’équipement agricole

•technicien de glaces de véhicule automobile

•technicien en peinture et en finition de véhicules automobiles

•mécanicien de véhicules automobiles

•technicien de véhicules automobiles

(mécanicien en station-service)

•technicien d’équipement lourd

The action below doesn't remove any of the bullets.

The same pattern seems to work just fine with the same text in BBEdit.

Post a test-case macro...

Take Care,
Chris

(Keyboard Maestro Moderator)

FWIW:
Paste plain and trimmed.kmmacros.zip (2.2 KB)

( ?m)^(•|▪|●|♦|\-|–|−|¬|¬)
  ↑ You have a misplaced space character...

The correct pattern:

(?m)^(•|▪|●|♦|\-|–|−|¬|¬)

1 Like

Ha! Thanks. Seems to be working now.

Show works well – tell very rarely helps as much as we expect.

1 Like