Help with regular expressions

Hiya

I would like some help with regular expressions to do the following:

I have lines of code which appear as following:

if ( variable1 == rhs.variable1 ) x = 2;

where "variable1" changes from line to line e.g. variable1 could be something like

if ( xyz== rhs.xyz) x = 2;

I want to replace all these lines with the following:

if ( allocate( variable1, rhs.variable1 ) ) x = 2;

where allocate is a function.

Can anybody tell me how to use regular expressions so I can do a replace on the source file so I can make the changes?

Thanks in advance

John
IssacJonesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Which IDE and version are you using?
0
käµfm³d 👽Commented:
I believe the following would help you, but it would be dependent on what you are using to do the find/replace (e.g. the IDE, external text editor, etc.). Some editors use their own special syntax for regexes. The pattern below is based on Perl regex patterns (which most other engines use).
Find:

    if\s*\(\s*(\w+)\s*==\s*(\w\.\1)\)\s*(\w+\s*=\s*\w+;)

Replace:

    if ( allocate( $1, $2 ) ) $3

-- if the above replace doesn't work, try

    if ( allocate( \1, \2 ) ) \3

Open in new window

0
IssacJonesAuthor Commented:
Hi kaufmed

Visual Studio 2008

John
0
käµfm³d 👽Commented:
OK. Change the syntax to:
Find:

    if:b*\({:i}:b*==:b*{:i\.\1}\):b*{:i:b*=:b*:a+:b*;}

Replace:

    if ( allocate( \1, \2 ) ) \3

-- if the above replace doesn't work, try

    if ( allocate( \1, \2 ) ) \3

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
Ignore the "-- if the above ..." part above....  I forgot to erase it  :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.