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

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?

You need (?x) flag, see example at regex - Rust

4 Likes

Ah yes, thanks!