|
|
#1 |
|
Triple-A Player
Join Date: Dec 2006
Location: Switzerland
Posts: 174
|
find and replace function
I have a few documents with lots of text that I have to replace.
For example I have to replace: <div id="answer1" style="visibility:hidden; color:brown" > <div id="answer2" style="visibility:hidden; color:brown" > <div id="answer3" style="visibility:hidden; color:brown" > ............................................................................... <div id="answer154" style="visibility:hidden; color:brown" > That means that I have to replace 154 pieces of text that are almost similar, with <div class="A">A:<div> Is there a way to automate this process? I'm using OS 10.7 and dreamweaver CS5.5 I appreciate your help |
|
|
|
|
|
#2 |
|
League Commissioner
Join Date: Aug 2006
Posts: 5,040
|
You don't need to AppleScript, you can just use a regular expression in the DreamWeaver Find and Replace dialog.
http://www.adobe.com/devnet/dreamwea...s_pt2.edu.html |
|
|
|
|
|
#3 |
|
League Commissioner
Join Date: Sep 2003
Location: Tokyo
Posts: 6,050
|
And the expression you want is:
Find: <div id="answer[0-9]*" style="visibility:hidden; color:brown" > Replace: <div class="A"> Or a better html option (and simpler replacement): style="visibility:hidden; color:brown" class="answer" this way you keep the ID. |
|
|
|
|
|
#4 | |||||||||||||||||||||||
|
League Commissioner
Join Date: Aug 2006
Posts: 5,040
|
Though this will affect other tags with those attributes, which may cause problems. |
|||||||||||||||||||||||
|
|
|
|
|
#5 | |||||||||||||||||||||||
|
Triple-A Player
Join Date: Dec 2006
Location: Switzerland
Posts: 174
|
Great, it works ! Thank you so much. As I also have 154 questions I then tried to replace the following: <div id="question1" onclick="Answer('question1','answer1','red','green');" style="color:blue" > <div id="question2" onclick="Answer('question2','answer2','red','green');" style="color:blue" > <div id="question3" onclick="Answer('question3','answer3','red','green');" style="color:blue" > .....................until question 154 with: Find: <div id="question[0-9]*" onclick="Answer('question[0-9]*','answer[0-9]*','red','green');" style="color:blue" > but no way to make it work, it doesn't find . Why? |
|||||||||||||||||||||||
|
|
|
|
|
#6 |
|
Triple-A Player
Join Date: Dec 2006
Location: Switzerland
Posts: 174
|
After a long internet search I got it:
<div(.*)blue" > Thank you, you made my day. |
|
|
|
|
|
#7 |
|
MVP
Join Date: May 2004
Posts: 2,012
|
It probably didn't match because the parentheses were being treated as groups, rather than plain characters. Similarily, your solution probably doesn't need the parens as you aren't doing anything with what is matched by the .*
You can capture matched text and then insert it in the replacement using parens to group the capture during the match and backreference characters in the replacement ($1, $2 or \1, \2 depending on the implementation).
__________________
i am jack's amusing sig file |
|
|
|
|
|
#8 | |||||||||||||||||||||||
|
Triple-A Player
Join Date: Dec 2006
Location: Switzerland
Posts: 174
|
It works with parenthasis but I will keep in mind your advise for next time. Thank you. |
|||||||||||||||||||||||
|
|
|
|
|
#9 | |||||||||||||||||||||||
|
League Commissioner
Join Date: Sep 2003
Location: Tokyo
Posts: 6,050
|
That's just..... nasty. How about: HTML: Code:
<div id="question2" class="question"> Code:
.question { color: blue; }
Code:
jQuery(document).ready( setupQuestions );
function setupQuestions() {
jQuery('.question').click( function() {
event.preventDefault();
var param2 = this.id.replace('question','answer');
Answer(this.id, param2, 'red', 'green');
});
}
Don't forget to load jQuery. |
|||||||||||||||||||||||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|