?
Solved

Regular Expression in Visual Studio 2008

Posted on 2009-05-07
12
Medium Priority
?
429 Views
Last Modified: 2013-11-26
Hiya

I have a long list of variables which I need to add to a copy constructor e.g.

x1 = rhs.x1;
y4 = rhs.y4;
z100 = rhs.z100;
y8 = rhs.y8;

etc. (involving hundreds of variables).

Now I have another list which looks like this:

x1 = 2.34;
y4 = 8888;
z100 = 3.2;
y8 = FALSE;

etc.

I feel there must be a way to use regular expressions to convert the second list into the first.

Can anybody tell me how to do this using regular expressions in Visual Studio 2008 (MFC) i.e. from the VS editor.

Thanks

John


0
Comment
Question by:IssacJones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
12 Comments
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24325183
having so many variables seems problematic to me... but that's another subject.

If it is all rhs.[+original name] on the right side, you can do this:

find: ^([^ ]+).*
replace: $1 = rhs.$1
0
 
LVL 39

Expert Comment

by:abel
ID: 24325192
oh, I forgot the closing semi colon:

replace: $1 = rhs.$1;
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24325345
If within the editor you mean inside the Find/Replace box, then your regex would be:
Find:
    ^{[^:b]+}.+
 
Replace:
    \1 = rhs.\1

Open in new window

0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 500 total points
ID: 24325360
Sheesh...  Same mistake as Abel :P

With semicolon:
Find:
    ^{[^:b]+}.+
 
Replace:
    \1 = rhs.\1;

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24325743
lol

dollar syntax doesn't work in replace box? Ah, the whole syntax is different. Great, I always forget that. Just tested a bit with mine and yours and since most of the time the code is indented, I come up with this blended expression:

find:    ^{:b+[^:b]+}.*

replace:    \1 = rhs.\1;
0
 
LVL 39

Expert Comment

by:abel
ID: 24326090
tx for the grade but...

this seems to be the day that the splitting points button is not found by the askers.. you are the fourth already. Are you aware of the possibility to split points if more experts have worked towards a solution?

If you still want to do that, please use the Request Attention button to ask for reopening of the question and once a moderator has done so (can take a few hours) you can reassign the split points.
0
 

Author Comment

by:IssacJones
ID: 24326176
hi abel, kaufmed

you prememted an email to experts exchange. I had indeed wanted to split the points but something strange happened during the allocation (which wasn't helped by my screen freezing and having to re-boot). I will attempt to split the points again.
0
 
LVL 39

Expert Comment

by:abel
ID: 24326324
aha, good news ;) (actually, not so good for me, because I will earn less points lol).
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24327292
abel...  I must say: You are a gentleman, sir. In any event, I was upset at myself for forgetting that the lines in the editor had leading space!! :)
0
 
LVL 39

Expert Comment

by:abel
ID: 24327329
Don't be upset about silly things like that. I only found out by experimenting myself. Often, obvious things are only obvious once discovered ;-)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24327545
Yeah. I'm over it now (patching the hole in the wall) ;)

j/k
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question