Hello, I´m new in programming, I am trying to erase something from the lines of a file,
example:
file is made of to colums:
xxxx zzzz
aaaa tttt
dddd nnn
I want to erase the second colum, what I am trying to do is to use the replace funtion, like this: (there a common pattern it is " XXXX" two spaces and the letters beyond). my code is something like this:
var1=(" *")
var2=("---")
f = open("archive.txt",'r')
change = f.read()
change = change.replace(var1,var2)
f.close()
new = open("newarchive.txt",'w')
new.write(change)
new.close()
the problem is the regular expression I am using " var1=(" *") "
" *" it is not working it does no match my lines, I have tried literally everything I found in internet but no luck
if I try:
var1=(" ")
var2=("---")
f = open("archive.txt",'r')
change = f.read()
change = change.replace(var1,var2)
f.close()
new = open("newarchive.txt",'w')
new.write(change)
new.close()
it replace only the two spaces with --- "xxxx---zzzz" and I need only the "xxxx---" with out the text beyond (zzzz)
what regular expression match " something" (spaces plus some alphanumeric text?) ? thanks for your time.
example:
file is made of to colums:
xxxx zzzz
aaaa tttt
dddd nnn
I want to erase the second colum, what I am trying to do is to use the replace funtion, like this: (there a common pattern it is " XXXX" two spaces and the letters beyond). my code is something like this:
var1=(" *")
var2=("---")
f = open("archive.txt",'r')
change = f.read()
change = change.replace(var1,var2)
f.close()
new = open("newarchive.txt",'w')
new.write(change)
new.close()
the problem is the regular expression I am using " var1=(" *") "
" *" it is not working it does no match my lines, I have tried literally everything I found in internet but no luck
if I try:
var1=(" ")
var2=("---")
f = open("archive.txt",'r')
change = f.read()
change = change.replace(var1,var2)
f.close()
new = open("newarchive.txt",'w')
new.write(change)
new.close()
it replace only the two spaces with --- "xxxx---zzzz" and I need only the "xxxx---" with out the text beyond (zzzz)
what regular expression match " something" (spaces plus some alphanumeric text?) ? thanks for your time.