Amit
Amit

Reputation: 1885

Refactoring regular expression needed

Can you please help me with a regular expression that I need for some code refactoring? I am trying to change the following

    something a.executeQuery() something else
    something b.executeQuery() something else
    something c.executeQuery() something else

to

    something someClass.executeQueryEx(a) something else
    something someClass.executeQueryEx(b) something else
    something someClass.executeQueryEx(c) something else

Basically trying to bring all DB calls to a central function, so that I can log them and do error handling at one place.

Upvotes: 0

Views: 43

Answers (1)

gog
gog

Reputation: 11347

Assuming a,b,c are just identifiers, you can simply replace

 (\w+)\.executeQuery\(\)

with

 someClass.executeQueryEx(\1)

or

 someClass.executeQueryEx($1)

depending on your regex engine.

If they can be arbitrary expressions, as in foo(quux).bar[25].executeQuery() I don't think you can do that with regexes alone.

Upvotes: 2

Related Questions