Allyssa
Allyssa

Reputation: 63

How to remove all the # comment out line for many files?

I have some files and I want to remove all the code after # (comment out),

maybe I want to import all the file and copy it line by line and ignore the # lines

I don't know what kind of tool or langauge should I use.

For example

AAA
BBB
#123
#456
CCC

I hope I can get

AAA
BBB
CCC 

but not

AAA
BBB


CCC

I tried to use regex to do replace the # line in "" but I doesn't work

str.replace(/\r/g,"")

enter image description here

I tried to detect what is the blue area, it said 6 spaces.

Upvotes: 0

Views: 267

Answers (1)

Sarah Groß
Sarah Groß

Reputation: 10879

As a related answer giving example python code has already been posted, here's a working solution in JavaScript. The RegEx pattern I use also matches Windows-style carriage return line breaks.

var string = `AAA
BBB
#123
#456
CCC`;

console.log(string.replace(/^#.*\r?\n/gm, ''));

Upvotes: 1

Related Questions