For a project I have to extract the RGB values from a file which are defined as following:
#71=IFCCOLOURRGB($,0.75,0.73,0.6800000000000001);
#98=IFCCOLOURRGB($,0.26,0.22,0.18);
I want to retun the RGB data and write it to a new file like this:
0.75 0.73 0.68
0.26 0.22 0.18
So far I've created this for loop:
import re
IfcFile = open('IfcOpenHouse.ifc', 'r')
IfcColourRGB = re.compile('ifccolourrgb', re.IGNORECASE)
for rad_rgb_data in IfcFile:
if re.search(IfcColourRGB, rad_rgb_data):
print(IfcColourRGB.sub('', rad_rgb_data))
This returns:
#71=($,0.75,0.73,0.6800000000000001);
#98=($,0.26,0.22,0.18);
Now I am quite new to programming and I want to know if I've chosen the right approach for my task, I've been reading about regular expressions but I don't fully understand how to get rid of all the #=(,: characters and how to exactly specify which numbers you want returned and which not. Is it possible to define all regular expressions explicitly/individually and combining them in one for loop so I have an easier time understanding them?