Regular expressions are your friend

Posted on:October 22 2005

I just wanted to replace several but not all .bmp textures with jpegs. Started editing the .xml file. Wait! Too tired to type, lets quickly write a regex: Find {"gamedata\\levels\\level02\\textures\\}{.*}{bmp"} and replace with \1\2jpg". Result:

Doh! I would have typed a lot for this doing it manually.





Comments:


just one tiny question: is it necessary to use two groups? (regular expressions for DOS-style paths in C/C++/... are a bit annoying, as backslashes quadruple, like in "C:\\\\Windows").
bertl
Quote
2005-10-24 09:44:00


hey, somehow my backslashes have gone away...
bertl
Quote
2005-10-24 18:09:00


For Windows you do not have to use the backslash you can the forward slash for folder and file paths instead so you do not have to double up the back slashes
TSM
Quote
2005-10-24 18:15:00


maybe the way I did the regex is not the simplest way but at least it works.. :)
niko
Quote
2005-10-24 20:58:00


while this is true it is hard to get any standard program to list files with forward slashes instead of backslashes (and users also find this pretty strange typically).
bertl
Quote
2005-10-25 10:12:00


Add comment:


Posted by:


Enter the missing letter in: "?nternational"


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons