Main Area and Open Discussion > General Software Discussion
SciTE regex replacement
MilesAhead:
I can't seem to get SciTE to regex replace for me. All I'm trying to do is stick a '_' in front of every line where the start of the line has [a-zA-Z].
If I use ^[a-zA-Z] in the search field, it pics it up. But no matter what I put in the Replace field after the underscore, it replaces the first character with the underscore instead of sticking the underscore in front. I think the '^' denoting start of line is messing me up.
Seems like it should be something simple that's done all the time. Damned if I can figure it out though.
Here's an example. I have functions like
MyFunc(param)
SomeFunc(param)
ThisFunc(param)
After the replacement I should have
_MyFunc(param)
_SomeFunc(param)
_ThisFunc(param)
Why is it so difficult?
jgpaiva:
If you try to replace "^[a-zA-Z]" with an underscore, it'll always match the first character, it's supposed to. Have you tried using only "^" (which denotes only the start of the line)?
MilesAhead:
Ok, a more accurate representation of the problem is this
funcName(param)
{
; some code
}
anotherFuncName(param1, param2)
{
; some more code
}
thirdFunc()
{
; yadda yadda
}
I only want the lines that start with [a-zA-Z] to start with _(funcnameline)
and not end up with
_funcName(param)
_{
_ ; some code
_}
jgpaiva:
Right, that makes sense. Then you need the expression to match the first character in the way you were doing before.
One way to solve the problem is to use:
regex: ^([a-Z])
replace: _$$1
This means: match the first character, replace with "_" concatenated with the character that was matched.
Depending on the regex engine, the "(" can also be "\(", and the "$$1" can be "$1" or "\1". (yep, it's annoying that not everybody follows the same syntaxes).
MilesAhead:
Thanks for your replies. In the meantime I got a response on ahk forum. Awk I could do a bit, but regex is not my strength. Easier just to write an app to read the input and spit out the output than figure this out. Here's the solution Lexicos posted:
http://www.autohotkey.com/community/viewtopic.php?f=1&t=89678&p=556410#p556399
Navigation
[0] Message Index
[#] Next page
Go to full version