Is there a nicer way to split a long regex over multiple lines?


#1

I have this regex in a lazy_static! block:

    static ref IDENTIFIER: Regex = Regex::new(
        &(r"^[_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lm}]".to_string() +
          r"[_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lm}\p{Nd}]*$")).unwrap();

Is there a nicer way to have a regex split over two or more lines?


#2

You need (?x) flag, see example at https://docs.rs/regex/1.0.1/regex/#example-replacement-with-named-capture-groups


#3

Ah yes, thanks!