I have some titles that start with # (as they are markdown), and I have the two following rules:
- titles (
#) should have exactly two newlines lines above and one underneath - subtitles (
##,###and so forth) should have exactly one blank line above and one below. - Titles should takes precedence over subtitles. (If there is two conflicting rules, use the title formatting and ignore subtitles).
NOTE: I'm trying to find all titles that does not conform to these three restrictions.
Below is some examples of good and bad titles
some text
# Title | BAD
## Subtitle | Good (Has two spaces below, is needed for next main title)
# Title | Good
## Subtitle | Bad
text
# Title | Bad
text
After fiddling around with regexp I came up with these expressions:
Main titles: Regexr
((?<=\n{4})|(?<=.\n{2})|(?<=.\n))(# .*)|(# .*)(?=(\n.|\n{3}(?!# )|\n{4}))
Subtitles: Regex
'((?<=\n{3})|(?<=.\n))(##+.*)|(##+.*)(?=\n.|\n{3}(?!# )|\n{4}.)'
However to my great confusion they don't work with pcregrep? Here is the command I tried to run with pcgrep (just for completeness sake):
$ pcregrep -rniM --include='.*\.md' \
'((?<=\n{3})|(?<=.\n))(##+.*)|(##+.*)(?=\n.|\n{3}(?!# )|\n{4}.)' \
~/Programming/oppgaver/src/web
It doesn't work either when I try to just search one file either and I have a couple other expressions that work just fine.
Is there something wrong with my regex, or is it a faulty implementation?