From 52fe1f7e4df3c801a0292b9ae78da1bb664c3e2e Mon Sep 17 00:00:00 2001 From: Cyprien de Saint Guilhem Date: Mon, 14 Oct 2024 22:19:16 +0200 Subject: [PATCH] Document added regex --- src/regexes.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/regexes.rs b/src/regexes.rs index b698b16..53b1905 100644 --- a/src/regexes.rs +++ b/src/regexes.rs @@ -51,7 +51,17 @@ lazy_static! { Regex::new(r"(?P\S.*?)(?P\\end\{)").unwrap(); pub static ref RE_ITEM_SHARED_LINE: Regex = Regex::new(r"(?P\S.*?)(?P\\item)").unwrap(); - pub static ref RE_ENV_ITEM_SHARED_LINE: Regex = - Regex::new(r"(?P\S.*?)(?P(\\begin\{|\\end\{|\\item ).*)") - .unwrap(); + // Regex that matches any splitting command with non-whitespace characters before it and catches the previous text + // in a group called "prev" and captures the command itself and the remaining text in a group called "env". + pub static ref RE_ENV_ITEM_SHARED_LINE: Regex = Regex::new( + r"(?x) # Enable extended mode + (?P\S.*?) # : captures any number of characters starting with a non-whitespace + # character until the start of the next group; + (?P( # : captures any LaTeX command before which the line should be split + \\begin\{ # start of environments + |\\end\{ # end of environments + |\\item ) # list items (note the space before the closing bracket) + .*)" // and any characters that follow the command + ) + .unwrap(); }