Copy and Past in Visual Studio and Fix IDs

When you copy a big chunk of ASP.NET code the chances are you are going to run int IDs problem. IDs from the new code is wiped as soon as you past them. Here is a solution to fix it.

Copy the chuck of code into clipboard and past into “Sublime Text 2” for example. Use the following RegPater to call all IDs.

RegEx pattern to get all IDS = (id=".*?)(")

Use the following patter in the replace text

Replace String: $1_2$2

Make sure you have select “Regular Expression” (there is a short cut button for it).
Replace everything it finds. And the copy and past the new code. This should fix the problem.

If your code has control validator, use the following regex as a second run to fix that issues

RegEx: (ControlToValidate=".*?)(")
Repalce String: $1_2$2

Please note, do not leave – character in ID as Visual Studio will automatically wipe that out.

This entry was posted in Regular Expressions, Software Development, Tutorials/Tips. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s