Index | FAQ | Search | Memberlist | Usergroups | Profile | Log in to check your private messages | Log in | Register

Regular Expressions + POSIX Dumping Grounds

| Inside3d Forums Forum Index -> General Programming

View previous topic :: View next topic
Author | Message
--- | ---
Baker Joined: 14 Mar 2006 Posts: 1538 |

Posted: Fri Dec 12, 2008 8:17 am Post subject: Regular Expressions + POSIX Dumping Grounds |

A few weeks ago, with the assistance of Lardarse, I managed to get regular expressions working. And after some more experience with it, I thought "This is so easy. I'll never forget". 1 month later ...

me.self wrote:
Ok ... aw, sh*t! It isn't working. What was it. How many brackets?

After burning 45 minutes I'll never get back re-remembering, I'm posting this here.
Perhaps someone else might benefit from this.
Regular Expressions in TextPad5
This is from the context of TextPad5. It's what I've used instead of NotePad for a long time. There are other fancy editors out there but so far all the other ones "do too much" for my liking.
It might be exactly the same as in Linux and in Perl or other things or might not be. My understanding is that RegExp and POSIX are a standard so you'd think this would transfer to just about any other Regular Expression queries.
In TextPad, I click Search -> Find in Files and I get greeted with this box.
I want to find EVERY instance of an OpenGL function being used in the original GLQuake source.
OpenGL functions all begin with "gl", but some of the functions in the engine begin with "GL" and a lot of cvars like gl_clear are lower case.

Quote:
glTexture2d - OpenGL function (wanted) GL_Init - engine initialization stuff, not wanted gl_clear - engine console variable, not wanted

So I want to find a lower-case gl followed by an upper case letter and then followed by a lower case letter.
So my regular expression is:

Quote:
gl [[:upper:]] [[:lower:]] - except there are no spaces ..

Did it work? ...
Yes, except I get some unwanted stuff like glRect -- that isn't a gl function, but of my matches, almost all of them are what I want.
Now, lets say I want to rename all the functions, maybe to reroute all the OpenGL interaction elsewhere in my code ... maybe to capture it or generate some statistics.
I could create duplicate functions like instead of glTexture2d XglTexture2d.
How would I rename those?
First, right click on the search results in TextPad and click "Open All". It opens all the files that search result matches.
Then I do Search -> Find and select "All Documents".
My find expression is the same. Except I need to flag the match part of the expression.

Quote:
Find text: gl [[:upper:]] [[:lower:]] -- "gl" followed by 1 uppercase letter and then 1 lower case New Find Text, we need to put \( \) around the match expression to preserve it in the replacement. New Find Text for replacement purposes: gl \( [[:upper:]][[:lower:]] \)
And the Replacement expression:
xgl\1 (the \1 preserves the regular expression part)

And here goes. Did it work?
All clear.

Back to top |

Display posts from previous:

| Inside3d Forums Forum Index -> General Programming | All times are GMT
Page 1 of 1

Jump to:

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2004 phpBB Group