This has been frustrating me for about 20 minutes already and I don't want to spend much more time on it, so any help would be much appreciated.

The editor that we use which syntax highlights Markdown text has has bug in which it highlights text as code when it isn't supposed to. The regex to denote code currently is /^(k:\t|\s{4,})/ which basically means find a line that begins with a tab or at least four spaces. I need to change this to say "find a line that is preceded by a blank line (aka by at least two \n\n) that then begins with a tab or at least four spaces.

Can anyone help me out? Thanks in advance!!! :)

Recommended Answers

All 4 Replies

This will match the first full line preceded by two newlines and a tab or at least four spaces:

((\n{2})(\t|\s{4,})(.*))

It's broken down into three capture groups:

  1. (\n{2}) finds the leading two newlines.
  2. (\t|\s{4,}) finds the leading tab or spaces.
  3. (.*) finds the actual content of the first line (the . operator doesn't match newlines by default).

But whether or not \n actually matches a newline in the content depends on what kind of transformations are done on the source string. If they're all <br />, \r, or \r\n then the regex will fail to match. That's probably why you've been having trouble.

Hi ... Yeah, I actually already tried that and it didn't work. It turns out that the parser uses "line-at-a-time" parsing, meaning that the string I'm looking at has no new lines in it at all because it's just the single line. Need to investigate more because I think it can be confusing that text shows up as code when it really isn't.

Can you modify the parser to save the last line?

Sorry for my delayed response. You should be able to, although I don't exactly know how :( But yes, that's the way that was recommended to me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.