Regex match multiline content

Hello all.

I’m trying to match this text format

#001
first line

#002
Multiple
Line

 #003
 third line

This pattern failed to match multiline content.

^\\s*(\\#\\d+)\\s*(?:[\\r\
])(.+)

This pattern will include everything after first line

^\\s*(\\#\\d+)\\s*(?:[\\r\
])((?:.|[\\r\
])+)

similar to this one

^\\s*(\\#\\d+)\\s*(?:[\\r\
])([\\s\\S]+)

Any idea how to make first pattern works as expected?

(?Umi-s)^[\\t\\x20]*(#\\d+)\\b[\\s\\S]+(?:\\R\\R|\\z)

I was just about to write:

“Hopefully Kem replies because he speaks fluent Klingon” :stuck_out_tongue:

You misspelled, “is a genus of the highest order.”

Er, genieus… gennious… geenyus?

:slight_smile:

I will take #3 (geenyus) for 300 :smiley:

[quote=378819:@Kem Tekinay] (?Umi-s)^[\\t\\x20]*(#\\d+)\\b[\\s\\S]+(?:\\R\\R|\\z) [/quote]
I would like to get some translation from Klingon to some algorithmic english ?

Wow, thank you Kem. Can you explain that?

I was trying this pattern ^\\s*(\\#\\d+)\\s*(?:[\\r\ ])[\\s\\S]+(?=\\#) but can’t match the last text (#003 ...)

My version looks for start of line, spaces/tabs, if any, then the “#” followed by numbers. It then matches everything until it either matches two consecutive EOL characters (\R) or the end of the document (\z). The key is to turn off Greedy with the (?U) switch. Otherwise, it will keep matching until the end of the document each time.

I didn’t know about \\R and \\z escape characters.

Thank you Kem, I understood now :slight_smile:

agreed.