File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -547,8 +547,16 @@ std::vector<T*> flat_filter(Pattern& pattern) {
547547}
548548
549549std::vector<std::string> parse_section (std::string const & name, std::string const & source) {
550+ // ECMAScript regex only has "?=" for a non-matching lookahead. In order to make sure we always have
551+ // a newline to anchor our matching, we have to avoid matching the final newline of each grouping.
552+ // Therefore, our regex is adjusted from the docopt Python one to use ?= to match the newlines before
553+ // the following lines, rather than after.
550554 std::regex const re_section_pattern {
551- " (?:^|\\ n)([^\\ n]*" + name + " [^\\ n]*\\ n?(?:[ \\ t].*?(?:\\ n|$))*)" ,
555+ " (?:^|\\ n)" // anchored at a linebreak (or start of string)
556+ " ("
557+ " [^\\ n]*" + name + " [^\\ n]*(?=\\ n?)" // a line that contains the name
558+ " (?:\\ n[ \\ t].*?(?=\\ n|$))*" // followed by any number of lines that are indented
559+ " )" ,
552560 std::regex::icase
553561 };
554562
You can’t perform that action at this time.
0 commit comments