use regular expression for advance editing

You have a loooooong select box, you want to change value field for each option and want to make it same as the option value. You can use regular expression to make the changes rather than edit every single line.


<select name=mylist>
<option value="1">one</option>
<option value="2">Two</option>
<option value="3">Three</option>

What you want is make the value, same as the text of option. Use the following regex. Basically you will be using groups to reference the two values and you will be reconstructing the matched string using the group values.

Regex Find (pattern) :([0-9]*)”>([A-Za-z ]*)
In replace (type this): $2″>$2

End Result

<select name="mylist">
<option value="One">one</option>
<option value="Two">Two</option>
<option value="Three">Three</option>

The first group is reference by $1, the second group is references by $2 and so on. Here we are skipping $1 in replace since it contains the numbers only which we do not want to use in replace.

This entry was posted in Uncategorized. 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