[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Regular Expression to place DIV around INPUTs

Posted on 2009-12-18
5
Medium Priority
?
908 Views
Last Modified: 2012-05-08
Hi there,

In the attached code snippet, I need:

<form method="post" action="Default.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">
<div>
<input type="hidden" name="__SPSCEditMenu" id="__SPSCEditMenu" value="true" />
<input type="hidden" name="MSOWebPartPage_PostbackSource" id="MSOWebPartPage_PostbackSource" value="" />
<input type="hidden" name="MSOTlPn_SelectedWpId" id="MSOTlPn_SelectedWpId" value="" />
<input type="hidden" name="MSOTlPn_View" id="MSOTlPn_View" value="0" />
<input type="hidden" name="MSOTlPn_ShowSettings" id="MSOTlPn_ShowSettings" value="False" />
<input type="hidden" name="MSOGallery_SelectedLibrary" id="MSOGallery_SelectedLibrary" value="" />
<input type="hidden" name="MSOGallery_FilterString" id="MSOGallery_FilterString" value="" />
<input type="hidden" name="MSOTlPn_Button" id="MSOTlPn_Button" value="none" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
</div>

with:

<form method="post" action="Default.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">
<div>
<div><input type="hidden" name="__SPSCEditMenu" id="__SPSCEditMenu" value="true" /></div>
<div><input type="hidden" name="MSOWebPartPage_PostbackSource" id="MSOWebPartPage_PostbackSource" value="" /></div>
<div><input type="hidden" name="MSOTlPn_SelectedWpId" id="MSOTlPn_SelectedWpId" value="" /></div>
<div><input type="hidden" name="MSOTlPn_View" id="MSOTlPn_View" value="0" /></div>
</div><input type="hidden" name="MSOTlPn_ShowSettings" id="MSOTlPn_ShowSettings" value="False" /></div>
<div><input type="hidden" name="MSOGallery_SelectedLibrary" id="MSOGallery_SelectedLibrary" value="" /></div>
<div><input type="hidden" name="MSOGallery_FilterString" id="MSOGallery_FilterString" value="" /></div>
<div><input type="hidden" name="MSOTlPn_Button" id="MSOTlPn_Button" value="none" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /></div>
<div><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /></div>
</div>

Thanks,

Ben
<form method="post" action="Default.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">
<div>
<input type="hidden" name="__SPSCEditMenu" id="__SPSCEditMenu" value="true" />
<input type="hidden" name="MSOWebPartPage_PostbackSource" id="MSOWebPartPage_PostbackSource" value="" />
<input type="hidden" name="MSOTlPn_SelectedWpId" id="MSOTlPn_SelectedWpId" value="" />
<input type="hidden" name="MSOTlPn_View" id="MSOTlPn_View" value="0" />
<input type="hidden" name="MSOTlPn_ShowSettings" id="MSOTlPn_ShowSettings" value="False" />
<input type="hidden" name="MSOGallery_SelectedLibrary" id="MSOGallery_SelectedLibrary" value="" />
<input type="hidden" name="MSOGallery_FilterString" id="MSOGallery_FilterString" value="" />
<input type="hidden" name="MSOTlPn_Button" id="MSOTlPn_Button" value="none" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
</div>

Open in new window

0
Comment
Question by:webtechy
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Hube02
ID: 26082208
What language are we doing the replacement in?
0
 
LVL 2

Author Comment

by:webtechy
ID: 26082229
I have a custom httpModule (C#.Net) that uses an XML file to do the search/replace, see example attached.
<expression>
		<find><![CDATA[<H2>(.*?)</H2>]]></find>
		<replacewith><![CDATA[<h2>$1</h2>]]></replacewith>
		<active><![CDATA[Y]]></active>
		<matchcase>TRUE</matchcase>
	</expression>

Open in new window

0
 
LVL 18

Assisted Solution

by:Hube02
Hube02 earned 1000 total points
ID: 26082261
maybe something like:


<expression>
                <find><![CDATA[<input[^>]*>]]></find>
                <replacewith><![CDATA[<div>$1</div>]]></replacewith>
                <active><![CDATA[Y]]></active>
                <matchcase>TRUE</matchcase>
        </expression>

Open in new window

0
 
LVL 2

Accepted Solution

by:
webtechy earned 0 total points
ID: 26083292
Needs to be specifically the hidden ones at the start of the page. So have amended to (also need to create a grouping):
<expression>
    <find><![CDATA[(<input type="hidden")([^>]*)(/>)]]></find>
    <replacewith><![CDATA[<div>$1$2$3</div>]]></replacewith>
    <active><![CDATA[Y]]></active>
    <matchcase>FALSE</matchcase>
  </expression>

Open in new window

0
 
LVL 2

Author Comment

by:webtechy
ID: 26083404
Closing
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

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

829 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