Regular Expressions + POSIX Dumping Grounds
Posted: Fri Dec 12, 2008 8:17 am
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 ...
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.
So my regular expression is:
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.
And here goes. Did it work?
All clear.
1 month later ...
After burning 45 minutes I'll never get back re-remembering, I'm posting this here.me.self wrote:Ok ... aw, sh*t! It isn't working. What was it. How many brackets?
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.
So I want to find a lower-case gl followed by an upper case letter and then followed by a lower case letter.glTexture2d - OpenGL function (wanted)
GL_Init - engine initialization stuff, not wanted
gl_clear - engine console variable, not wanted
So my regular expression is:
Did it work? ...gl [[:upper:]] [[:lower:]] - except there are no spaces ..
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.
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.