Skip to content

Flipping Assignments With Regexs

January 5, 2009

Don’t you hate those forms you sometimes have to build where you load values for a ton of controls and then have to basically reverse the statements later on to save the values?  I found an easy way to flip the statements on the equals sign using regular expressions in Notepad++.  Neato!

CropperCapture[1]

Essentially we’re creating two groups.  (.+) is the first group [=] marks the end and (.+) is the second with ; excluded.

From here we can simply say \2 = \1; is our replacement.

CropperCapture[2]

This particular example isn’t quite as clean because I was doing a bit tweaking to the values but it still saves me a ton of time only having to trim up a few lines rather than rewriting them or doing lots of copy / pasting.

Advertisements
No comments yet

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: