Skip to content

Commit

Permalink
update regex to remove also lines under the statement
Browse files Browse the repository at this point in the history
  • Loading branch information
chainyo committed Apr 21, 2024
1 parent 462ef51 commit 120b09c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use std::io::{self, Write};

fn clean_file(path: &str) -> io::Result<()> {
let data = fs::read_to_string(path)?;
let re = Regex::new(r#"if __name__ == ['\"]__main__['\"]:\s*"#).unwrap();
// Updated regex to match the if statement and any indented lines that follow
let re = Regex::new(r#"if __name__ == ['\"]__main__['\"]:\s*\n( +.*\n)*"#).unwrap();
let cleaned = re.replace_all(&data, "");

fs::write(path, cleaned.as_ref())?;
Expand Down

0 comments on commit 120b09c

Please sign in to comment.