Replace recursively

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Flatron
Forum Newbie
Posts: 1
Joined: Sat Feb 02, 2008 7:51 am

Replace recursively

Post by Flatron »

Hi!

I have a lot of variables, and I would like to make a Get function for each. E.g.:
from:

Code: Select all

int var1, var2;
to:

Code: Select all

public int Getvar1()
{
    return this.var1;
}
public int Getvar2()
{
    return this.var2;
}
the problem is that the int is not constant, it could be any other type.
I tried with this:

Code: Select all

[\s]*([\w]+)(?:[ ]([\w]+),?)+;
This matches the string, but makes a replacement only for var2.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Replace recursively

Post by Christopher »

Maybe you could use __call() instead to implement your getters? I think there are examples in the manual.
(#10850)
Post Reply