use regex::Regex;

fn main() {
    let ws_re = Regex::new(r"\s+").unwrap();
    let clean_str = |s: &str| -> String {
        let mut s = ws_re.replace_all(s, " ").into_owned();
        loop {
            let last = s.clone();
            for token in ["(", ")", ",", "{", "}", "\"", "=", "'"] {
                s = s.replace(&format!(" {}", token), token);
                s = s.replace(&format!("{} ", token), token);
            }
            if s == last { break; }
        }
        s.trim().to_string()
    };
    
    let input = "INSERT INTO agreego.\"entity\" ( \"created_at\"";
    println!("Expected: {}", clean_str(input));
}
