Help With Regex to Delete All Lines Containing Strikethrough Markdown Text (Double Tilde ~~)

Macos Tahoe, Bear Pro App (Markdown Notes)

what I would like to do

1- in selected text in a Bear (markdown) note

2- delete all lines containing strikethrough text (all lines containing at least on double tilde ~~

3- delete the resulting blank lines, and any other blank lines

I go so far as to be able to delete blank lines in Bear markdown: replace (?m)^\n with "" (blank)

I searched the internet to no avail.

thank you very much

Does this do the trick?

(?m)^.*~~.*$

no, it does nothing. I tried your formula 2 ways: regex clipboard filter and using the BBEdit text factory. thank you for taking the time to think about it.

Put @Alexander’s regex in a Search and replace action and you should find that it works (assuming there are no mistakes, e.g. it’s not actually the clipboard that is being searched). See the example below. If your macro still doesn’t work, please upload it, together with an example of text that is to be searched.

Remove lines that contain a pair of tildes..kmmacros (2.8 KB)

I suspect that what a “line” is might be the issue.

or by zero regex (split and filter):

return kmvar.local_Clip
.split(/\n+/)
.filter(x => !x.includes('~~'))
.join('\n')


Remove lines that contain a pair of tildes..kmmacros (3.4 KB)

thank you @ComplexPoint @kevinb @Alexander Just to let you know I am working on it. thanks very much for your posts and macros. I will give you an update.

In the end, @Alexander ‘s solution works perfectly. it was a question not of the filter itself, but the way I first copied the selected text. Simple Text and RTF (ie the copy KBM action) did not work, but all is fine with copy as Markdown which is not the default. A simple copy copied as RTF.

@ComplexPoint and @kevinb : thank you very much for the java scripts which unfortunately did not work.

thank you all 3 very very much for your efforts and insights !

I have a bunch of subroutines for text processing. Here's one that you might like to try:

REMOVE Lines Containg String.kmmacros (35 KB)

Macro screenshot

Example usage:

There we are! Give the guy a :check_box_with_check:! :grinning_face_with_smiling_eyes:

I wouldn’t even take credit for Javascript that doesn"t work. :upside_down_face: I think there might have been misunderstandings about what text format you were working with:

Original post:

Latest reply:

If the original was in plain text (markdown), where does RTF come into the picture?

because Bear Notes have multiple possibilities of copy

great ! thank you very much. I am keeping it as a template. Just curious: it does not seem that I can use it to delete blank lines ?

I still don’t see how ending up in RTF territory was inevitable, but alright, that might just be down to my lack of experience with Bear.

OP:

So where exactly are you stuck?

it was not inevitable. It was my error.

it’s fine. I just run the filters sequentially.

thank you

When you select the text in Bear it'll show the Markdown formatting:

...but if you "Copy" that selection it will be RTF and the plain text equivalent:

To get the raw Markdown on the Clipboard you need to "Copy As -> Markdown".

I think @Ronald's doing himself a disservice -- I'd also expect to get raw Markdown when that's what is highlighted!

yes, I now realize that you are right. thank you

I see! Now I understand that “A simple copy copied as RTF” was a reference to the default option that wasn’t used in the final macro. Thanks for bearing with me. :teddy_bear:

exactly Thank you