Regular Expression N00bie needs help :P

Loffen

Well-known member
Joined
Mar 21, 2004
Messages
51
Location
Akershus, Norway
I am actually coding a map-loader class for my game. In the beginning the map format was quite simple, and i could just read line after line and put things together. Now, my mapformat is getting more complicated, and its much easier to make the whole thing crash. I have done some PHP and i know what regular expressions are, but i never bothered to learn them (mostly because i never needed them), but i think thats the thing i have to use..

My maps are separated into four sections. Config, Terrain data, Object data and Trigger data. I want to read the whole file, then split it up using reg expr. To clearify this ill make an example:

The map:
Code:
[MAP_CONFIG:
map_name=Testmap
map_tileset=Default
]
[MAP_TERRAIN_DATA:
0;1;0;1;0;1;0;1;
0;1;0;1;0;1;0;1;
0;1;0;1;0;1;0;1;
0;1;0;1;0;1;0;1;
]
[MAP_OBJECT_DATA:
tree{pos=2,2;}
tree{pos=6,3;}
]
[MAP_TRIGGER_DATA:
hurt{pos=0,0;dmgamount=10;}
]

Here id like to separate the config, terrain data etc, like this:

ConfigVar =
Code:
map_name=Testmap
map_tileset=Default

TerrainDataVar =
Code:
0;1;0;1;0;1;0;1;
0;1;0;1;0;1;0;1;
0;1;0;1;0;1;0;1;
0;1;0;1;0;1;0;1;

etc...

I really have no ideas how to do this. If you know some good tutorials, please post them here. Suggestions?? I dont care if i have to change the map format a little...

-- Loffen
 
Last edited by a moderator:
I think you should consider writing the config in XML and using XMLSerialization. Itd be much easier than reading it using regular expressions.

There are plenty of web sites and books offering regular expression tutorials. You may find this site helpful, not for tutorials, but there is a pattern testing page and some good example patterns.

http://www.regexlib.com

John
 
Thanks John!

I peeked into the site already befor i posted, but i couldnt find anything i could use. I figured i can just use normal Split() function. This will be more code, but i think it will be easier to read.

-- Loffen
 
Back
Top