What makes a forecast in Regex?

I need help decoding Regex

(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1 

This came from showdown.js

 (\*\*|__) match ** or __ (?=\S) -> look ahead for *one* non-space character? what for? ([^\r]*?\S[*_]*) -> zero or more non-carriage-returns, why newlines \n allowed?, one non-space, zero or more * or _ characters \1 ends with 1st capture: ** or __ 

Basically I do not get the 2nd and 3rd row

+4
source share
1 answer

I'll take a hit in the second part (remember, I suppose, based on the knowledge that this is a JS Markdown parser):

The lookahead statement (?=\S) probably exists if someone wants to write two asterisks ** or two underscores __, not wanting to highlight the text that comes after it, which is separated by a space (see what I did there? )

 ** This text will not be bold. ** **This text will be bold.** 

** This text will not be in bold. **
This text will be in bold.

+2
source

All Articles