• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

Regex Find and Replace

Hi,
I am looking for some regex FIND AND REPLACE solutions, as I've forms who has 100's of checkboxes and radio buttons. I am using Dreamweaver...

In first problem, i need a regex which only targets the name attributes of the inputs and add the code at the end of the input tags.

For eg: i've input 3 input checkboxes/radio tags and you see the attributes are not in same format and order.

<input name="Oriented" type="checkbox" id="Oriented" value="1" style="height:11px" />
<input name="Time" type="checkbox" id="Time" value="1" onClick="abc();" />
<input type="radio" name="OrientTime" id="OrientTimeA" tabindex="340" />

[b]LOOKS LIKE THAT AFTER REGEX FIND AND REPLACE[/b]
<input name="Oriented" type="checkbox" id="Oriented" value="1" style="height:11px" <cfif IsDefined("FORM.Oriented") AND FORM.Oriented EQ '1'>checked="checked" </cfif>/>
<input name="Time" type="checkbox" id="Time" value="1" onClick="abc();" <cfif IsDefined("FORM.Time") AND FORM.Time EQ '1'>checked="checked" </cfif>/>
<input type="radio" name="OrientTime" id="OrientTimeA" tabindex="340" <cfif IsDefined("FORM.OrientTime") AND FORM.OrientTime EQ '1'>checked="checked" </cfif>/>

Open in new window



In second problem, regex again targets the name attribute of input tags of checkboxes/radio buttons and format the tags.

for eg: i've 2 input tags.

<cfinput type="checkbox" name="Sputum" id="Sputum" tabindex="120" value="1">
<cfinput type="checkbox" name="vital" id="vital" value="1" required="yes" style="padding:4px;">

[b]LOOKS LIKE THAT AFTER REGEX FIND AND REPLACE[/b]
<cfif #Sputum# EQ 1>
<cfinput type="checkbox" name="Sputum" id="Sputum" tabindex="120" value="1" checked="yes">
<cfelse>
<cfinput type="checkbox" name="Sputum" id="Sputum" tabindex="120" value="1" checked="no">
</cfif>

<cfif #vital# EQ 1>
<cfinput type="checkbox" name="vital" id="vital" value="1" required="yes" style="padding:4px;" checked="yes">
<cfelse>
<cfinput type="checkbox" name="vital" id="vital" value="1" required="yes" style="padding:4px;" checked="no">
</cfif>

Open in new window


In third problem, regex targets the SECTION of <cfif IsDefined("FORM.OrientTime") AND FORM.OrientTime EQ '1'>checked="checked" </cfif> and replace'em.

for eg: I've 3 input tags.

<input name="Oriented" type="checkbox" id="Oriented" value="1" style="height:11px" <cfif IsDefined("FORM.Oriented") AND FORM.Oriented EQ '1'>checked="checked" </cfif>/>
<input name="Time" type="checkbox" id="Time" value="1" onClick="abc();" <cfif IsDefined("FORM.Time") AND FORM.Time EQ '1'>checked="checked" </cfif>/>
<input type="radio" name="OrientTime" id="OrientTimeA" tabindex="340" <cfif IsDefined("FORM.OrientTime") AND FORM.OrientTime EQ '1'>checked="checked" </cfif>/>

[b]LOOKS LIKE THAT AFTER REGEX FIND AND REPLACE[/b]
<input name="Oriented" type="checkbox" id="Oriented" value="1" style="height:11px" <cfif #Oriented# EQ '1'>checked="checked" </cfif>/>
<input name="Time" type="checkbox" id="Time" value="1" onClick="abc();" <cfif #Time# EQ '1'>checked="checked" </cfif>/>
<input type="radio" name="OrientTime" id="OrientTimeA" tabindex="340" <cfif #OrientTime# EQ '1'>checked="checked" </cfif>/>

Open in new window


Thanks in advace..
0
s_hausen
Asked:
s_hausen
  • 3
1 Solution
 
käµfm³d 👽Commented:
Try these:

Problem 1
Find:
(<input [^>]*name="([^"]+)"[^>]*)/>

Open in new window


Replace:
$1<cfif IsDefined("FORM.$2") AND FORM.$2 EQ '1'>checked="checked" </cfif>/>

Open in new window



Problem 2
Find:
(<cfinput [^>]*name="([^"]+)"[^>]*)/?>

Open in new window


Replace:
<cfif #$2# EQ 1>
$1 checked="yes">
<cfelse>
$1 checked="no">
</cfif>

Open in new window



Problem 3
Find:
(<input [^<]*<cfif )IsDefined\("FORM\.([^"]+)"\) AND FORM\.\2( EQ '1'>checked="checked" </cfif>[^>]*>)

Open in new window


Replace:
$1#$2#$3

Open in new window

0
 
käµfm³d 👽Commented:
P.S.

If the dollar symbols don't work in the replacement expressions, try using backslashes instead.

e.g.
\1#\2#\3

Open in new window

0
 
s_hausenAuthor Commented:
hi kaufmed,
all the regex's are working like charm. you really are a life saver. thanks a bunch, deeply appreciated.
0
 
käµfm³d 👽Commented:
NP. Glad to help  = )
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now