Welcome Guest.   Make a donation to an author on the site August 22, 2014, 06:37:33 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2014! Download dozens of custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: SciTE regex replacement  (Read 1484 times)
MilesAhead
Member
**
Posts: 4,773



View Profile WWW Give some DonationCredits to this forum member
« on: August 03, 2012, 05:21:31 PM »

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?


Logged

"Genius is not knowing you can't do it that way."
- MilesAhead
jgpaiva
Global Moderator
*****
Posts: 4,710



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: August 03, 2012, 06:03:15 PM »

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)?
Logged

MilesAhead
Member
**
Posts: 4,773



View Profile WWW Give some DonationCredits to this forum member
« Reply #2 on: August 03, 2012, 06:37:45 PM »

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
_}



Logged

"Genius is not knowing you can't do it that way."
- MilesAhead
jgpaiva
Global Moderator
*****
Posts: 4,710



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #3 on: August 03, 2012, 06:54:11 PM »

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).
Logged

MilesAhead
Member
**
Posts: 4,773



View Profile WWW Give some DonationCredits to this forum member
« Reply #4 on: August 03, 2012, 07:42:33 PM »

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...9678&p=556410#p556399

Logged

"Genius is not knowing you can't do it that way."
- MilesAhead
Edvard
Coding Snacks Author
Charter Honorary Member
***
Posts: 2,531



View Profile Give some DonationCredits to this forum member
« Reply #5 on: August 04, 2012, 10:06:34 PM »

Quote
(yep, it's annoying that not everybody follows the same syntaxes).

Yep, in Textpad 5, you use the '&' symbol to spit out what you matched, so you would replace like so:

Find:      ^[a-Z]
Replace: _&

:shrug:
Logged

All children left unattended will be given a mocha and a puppy.
MilesAhead
Member
**
Posts: 4,773



View Profile WWW Give some DonationCredits to this forum member
« Reply #6 on: August 05, 2012, 12:03:25 AM »

The main thing messing me up was putting the start of line symbol inside the pattern. I found PsPad makes it a bit easier than SciTE. This works in PsPad

find
^([a-zA-Z])

replace
_$1

and

[copy or print]
func(param)
{
  jive()
}

func2(param2)
{
  jive2()
}

is magically transformed into

[copy or print]
_func(param)
{
  jive()
}

_func2(param2)
{
  jive2()
}

It's a lot less confusing without the backslashes.
Logged

"Genius is not knowing you can't do it that way."
- MilesAhead
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.03s | Server load: 0.05 ]