I have markdown text in which the listed items (whole blocks of texts) with dashes follow one another. Because there are too many dashes, they are confusing. Let me explain.
I originally opted to use them instead of non-dashed indented text which are not suited for normal text. You see, in Markdown, if you just indent text as you would do in Word, for instance, the colour of the text changes and you cannot see your backlinks, hyperlinks or they don't "jump at you" as in normal formatted text. Hence, I was using regexes to convert text with indentations of 4, 8, 12 spaces to text headed by dashes for lists, because that way I could see the formatting in those blocks of texts properly.
In the meantime, I found out that I can keep the indentation "alive" by using the HTML tag <br/>. So the former CR/LF's done back in Word will be exchanged by these linebreaks but the dashes after the inital dash are no longer needed. In the meantime, I was using soft line breaks (two spaces after each block of text) (so the text would not be a continuous flow in Markdown preview mode), which might seem confusing here but no need to worry about those. I mean, they need to matched, but the soft line break plus the HTML line break code will not combine to cause issues.
Basically the whole idea of mine was using indents by way of lists so I can see the formatting in markdown. When you hit enter, though, the new list item with the dash will appear in the editor as well. Now with the knowledge of this tag, I can paste in the HTML tag and keep the indentation in place underneath without having to add/see the superfluous dashes everywhere. But when I converted my 15000 notes (with several VBA macros and many times playing around in Notepad++), these dashes are all over everywhere.
After an empty line or unindented block of text, I would need the first dash in place for indentation purposes and the rest gone. If there is a dash and a whitespace character by themselves, they are residues of bad regex converts from before. I could match and delete those later. I should have, as it was confusing one of the commenters.
In this Regex demo, I show an example with my match and replace lines.
As you can see, I can match some of the instances in the list, but not all of them.
I wonder how and where the \K or maybe \R operator or some other method can help with matching all instances.
If someone could have a look and give me insights, that would be great.
The double spaces after each line can stay in place as they cause no preview issues with the HTML tag.
So what I have now:
Main text flowing here. Then for indentation purposes blocks of text headed by dashes/lists (there is either an empty line or not):
- Text
- More text
- Even more text
- Yet more text
What I need is the first dash which serves as makeshift indentation for me in markdown and the rest are no longer needed with the HTML tag doing its job, which is not carry the text out to the main text area; I wanted the same level indentation to continue):
- Text
More text
Even more text
Yet more text
So basically after match and replace the text would look like this in Edit Mode (not in Preview Mode, Preview will look good if in Edit mode it looks like this) (Markdown editors vary but you can find some online as well, e.g. stackedit.io):
- Text with sentence ending period, exclamation mark, etc.
<br/>More text starting at same indentation level.<br/>Even more text continues at same indent level.<br/>Yet more text. (Normally 4-6 lines maximum. Usually I nest indents so the other less weighty arguments coming right underneath will be indented with 4 then 8 spaces before each dash.)
These conversions will need to be made for texts starting with four spaces and 8 spaces, but I guess I could tailor the solution to tackle those cases.
A commenter was asking about spaces; spaces are not needed because the line break will have the blocks of texts break up anyway.
Using (^-\s["1-9a-zA-ZÀ-ŰØ-űø-ÿ]+.*?[:.!?]\s{2})\n matches all, but then I won't be able to use the HTML tag to good effect, with the dashes staying in place because the second capture group is non-existent. I need both capture groups matched for all instances.
Adding *? after the first capture group almost does the trick, but not quite:
Regex demo update
The closest I could come on my own (the first dash is also removed in this instance, though): Regex demo 3
Unfortunately, though, this doesn't exactly work in Notepad++ or grepWin the way I want it.
Unfortunately (2), the provided ideas/regexes in the comment section did not work as expected, probably because the requirements were not understood. As I said in the comments, forget about the numbers in the example texts in Regex101, they are not important. If anything, they were good for only one thing: to match text not starting with normal ABC characters.
In the meantime I changed the group to capture [[(*"'1-9a-zA-ZÀ-ŰØ-űø-ÿ] even, because some texts may start with brackets and asteriks as well as accented characters.