Find/Replace - multiple replace ... maybe with regex
Hello Dreamweaver community ... I'm relatively new to using Dreamweaver as an editor and I'm working on a large migration project that I'm trying to make easier. Basically, I'm converting an entire site from English to Spanish ... almost literally tag by tag
Something that would make my job a lot easier is if ... every time I open a new Spanish language content file I could ...
replace ALL Spanish language grammar symbols, accents, tildes etc ... with their HTML equivalents ... for example ...
á = á
é = é
í = í
And so on ... there's about 10-12 major changes ...
What I need to figure out is how to save a find/replace query in Dreamweaver .dwr format that replaces all symbols at once instead of needing to do them one at a time ...
Seems like this shoudl be possible but I haven't figured out the right syntax ... I used the (.+) and $1 but it only worked conditionally - in the order the replacements were written. I need it to find ALL instances of a spanish symbol and replace it with its corresponding html ...
Can anyone help me with this ...?
Thank you in advance ...
This is in fact the only solution I found to this problem.
Creating an extension is not that difficult once you have the right
reference material.
Have a look at:
DW API function to find and replace
http://livedocs.adobe.com/en_US/Dreamweaver/9.0_API/dwr_code_cd_013.html
Sample extension file on your machine after installing DW
C:\Program Files\Adobe\Adobe Extension
Manager\Samples\Dreamweaver\
Full specifications of the MXI (extension file) format
http://download.macromedia.com/pub/exchange/mxi_file_format.pdf
quote:
Originally posted by:
Newsgroup User
> So, is it indeed possible to run more than one
find/replace query at a
> time?
As far as i know, no it's not possible.
There has been mentions in the past to this question that a
series of
find/replace queries could be built as a dw extension instead
of a saved
search query.
Alan
Adobe Community Expert, dreamweaver
Similar Messages
-
Replace multiple space characters with a single space
Hi,
Oracle 11g R2.
Looking for a way to replace multiple space characters in a row with a single space. For example, the text "abc abc" should look like "abc abc". I tried toying with replace, but it only works for the case of 2 spaces. Need a solution for the cases where there could be 2 or more spaces.
select replace(column1, chr(32)||chr(32), chr(32)) from tableaHi,
If you had to do this without regular expressions, you could use:
SELECT REPLACE ( REPLACE ( REPLACE (str, ' ', '~ ')
, ' ~'
, '~ '
) AS new_str
FROM table_x;assuming there is some sub-string (I used '~' above) that never occurs right next to a space.
However, unless you're uisng Oracle 9 (or earlier, which you're not doing) you don't have to do this without regular expressions. As you can see, the way Solomon showed is much simpler. -
Replacing multiple "replaces" with a cleaner/shorter version
Hi,
I have a script to clean up the names of files in a directory, removing rubbish entries. It runs something like this.
$newfile = $newfile -replace "-abc"
$newfile = $newfile -replace "-def"
$newfile = $newfile -replace "-ghi"
$newfile = $newfile -replace "-jkl"
The so, a file called "test -abc.txt" becomes test.txt, and a file called "test2 -abc -def.txt" becomes test2.txt
However, I'm sure there's a shorter, more elegant way of doing this, (there always is with PS).
e.g. I'd like to set up some form of input and array, something like.
variable = "abc", "def", "ghi"
foreach $entry in $variable { $newfile = $newfile - replace $entry"}
Unless I can simply pipe multiple entries directly into the replace?
thanks everyone,
GavinYou can specify multiple patterns inside a single regular expression, if this is going to just be hard-coded. If you want to do this dynamically, then your approach of looping over an array also has potential.
$newfile = $newfile -replace "-(abc|def|ghi|jkl)"
that's great!
and what about if I want to delete brackets... it doesn't seem to quite work when I do the following.
INPUT:
$dir = dir | where {!$_.psiscontainer}
$dir.fullname
foreach ($file in $dir)
$newfile = $file.basename -replace '[.]', " "
$newfile = $newfile -replace "-(abc|def|ghi|jkl|(|))"
"renaming "+$file.BaseName + " into $newfile"
rename-item $file.name $newfile
OUTPUT:
T:\Downloads\Test1 (-abc).txt
T:\Downloads\test2-abc ().txt
T:\Downloads\testbase.txt
T:\Downloads\testc-abc.txt
renaming Test1 (-abc) into Test1 ()
renaming test2-abc () into test2 ()
renaming testbase into testbase
renaming testc-abc into testc -
How do I replace multiple consecutive spaces with a single space?
I need to convert any occurrence of multiple consecutive spaces in a string to a single space. How do I create the regex pattern to do that?
r9973 wrote:
Sorry, more like: String test = "Some Text Here"Want to convert to String test = "Some Text Here"
Post the code that you used to test the regex. I just tried it and it worked fine for me. All you need to do is apply the regex replaceall to your string variable that holds the string
String test = "Some Text Here";
test = test.replaceAll(" +", " ");
System.out.println(test);And thats it. -
SQL Advice - Replace an OR maybe with regular expression?
Hello everyone,
I have a little question. This one is bothering me for weeks now and I was wondering if any of you have another idea for this.
Imagine the following table. It's a very stupid table. But look at the sample data. I reproduced the question that I have with the 3 records.
CREATE TABLE departments
dpt_id NUMBER(10),
dpt_name VARCHAR2(100)
INSERT INTO departments(dpt_id, dpt_name) VALUES(1, 'NIGER');
INSERT INTO departments(dpt_id, dpt_name) VALUES(1, 'NIGERIA');
INSERT INTO departments(dpt_id, dpt_name) VALUES(1, 'NIGER.0001');
SELECT *
FROM departments
WHERE (dpt_name = 'NIGER' OR dpt_name LIKE 'NIGER.%');If I use a LIKE NIGER%, I retrieve also NIGERIA (which I don't want). So, instead, I use this OR combination and it works well. But I was wondering if it is doable without this OR.
Thanks,Hi,
if you know the characters you will allow follwoing Niger, eg. dot and digits only you might consider using translate
SELECT *
FROM departments
WHERE translate (dpt_name, 'A0123456789.', 'A') like 'NIGER'
but this will match N9IGER too.
also regexp is possible
SELECT *
FROM departments
WHERE regexp_like (dpt_name, 'NIGER[^[:alpha:]]*$')Regards
Edited by: chris227 on 11.08.2012 09:38 -
Find and replace for multiple thin space with enter...
Hi,
Im new to the InDesign Scripting. I need to replace multiple thin space with enter to single enter. Dont know how to do. Pls someone help me.
Thanks in advance,
SudhaHi Sudha,
Use the Sample code,
app.findTextPreferences = null;
app.changeTextPreferences = null;
app.findChangeTextOptions.wholeWord = false;
app.findChangeTextOptions.caseSensitive = true;
app.findChangeTextOptions.includeMasterPages = false;
app.findTextPreferences.findWhat = "<2009>^p";
app.documents.item(0).findText();
app.changeTextPreferences.changeTo = "^p";
app.documents.item(0).changeText();
app.findTextPreferences = null;
app.changeTextPreferences = null;
Regards,
Nagaraj -
Replacing multiple spaces with a single space
Hi friends,
I have a string. It can have zero/one/multiple spaces. I want to make the multiple spaces to single space.
Here are the cases:
1. ' a b c d efg h' should be changed to 'a b c d e f g h'
2. ' a b c d e f g h ' should be changed to 'a b c d e f g h'
3. 'a b c d e f g h' should not be changed
4. 'abcdefgh' should not be changed
Both REPLACE and TRANSLATE do not help. I don't want to go for LOOP logic. Please help me to get it in SQL query.
Thanks in advance!Hi,
964559 wrote:
Hi friends,
I have a string. It can have zero/one/multiple spaces. I want to make the multiple spaces to single space.
Here are the cases:
1. ' a b c d efg h' should be changed to 'a b c d e f g h'One solution is to post your string on this site, and then copy it back again. (See below for a more serious solution .)
This site is doing exactly what you want the function to do: it replaces multiple consecutive spaces with a single space. As a result, it's hard to see what you mean.
To preserve spacing on this site, type these 6 characters
\(small letters only, inside curly brackets) before and after each section where you want spacing preserved.
2. ' a b c d e f g h ' should be changed to 'a b c d e f g h'
3. 'a b c d e f g h' should not be changed
4. 'abcdefgh' should not be changed
Both REPLACE and TRANSLATE do not help. I don't want to go for LOOP logic. Please help me to get it in SQL query.
Thanks in advance!Regular expressions make this easy:SELECT TRIM ( REGEXP_REPLACE ( str
, ' +'
) AS compressed_str
FROM table_x;
You can use nested REPLACE calls to get the same results, but it's messy.
Edited by: Frank Kulash on Feb 5, 2013 10:18 AM
Added TRIM -
Multiple replacements from an input file with 1.4 Regex
hi,
i'm trying to make multiple replacments to a source file <source> using a second input file <patterns> to hold the regex's. the problem i'm having is that the output file only makes the last replacement listed in the input file. Example if the input file is
a#123
b#456
only b is changed to 456 and a remains.
the second debug i've got shows that all the replacements are in memory, but i'm not sure how to write them all to the file.
the syntax is Java MyPatternMatcher <source> <patterns>
import java.util.regex.*;
import java.io.*;
import java.util.*;
public class MyPatternResolver {
private File patternFile;
private File sourceFile;
private Vector patterns = new Vector();
public MyPatternResolver(String sourceFile, String patternFile) {
this.sourceFile = new File(sourceFile);
this.patternFile = new File(patternFile);
loadPatterns();
resolve();
private void loadPatterns() {
// read in each line if File
FileReader fileReader = null;
try {
fileReader = new FileReader(patternFile);
} catch(FileNotFoundException fnfe) {
fnfe.printStackTrace();
BufferedReader reader = new BufferedReader(fileReader);
String s = null;
String[] strArr = new String[2];
try {
while((s = reader.readLine()) != null) {
StringTokenizer tokenizer = new StringTokenizer(s, "#");
for (int i =0; i < 2; i++) {
strArr[i] = tokenizer.nextToken();
//Debugging Info
System.out.println("Token Value " + i + " = " + strArr);
//End Debugging Info
patterns.add(new PatternResolver(strArr[0], strArr[1], sourceFile));
} catch(IOException ioe) {
ioe.printStackTrace();
private void resolve() {
Iterator iterator = patterns.iterator();
while(iterator.hasNext()) {
PatternResolver pr = (PatternResolver) iterator.next();
pr.resolve();
public static void main(String[] args) {
MyPatternResolver mpr = new MyPatternResolver(args[0], args[1]);
public class PatternResolver {
private String match, replace;
private File source;
public PatternResolver(String s1, String s2, File f) {
this.match = s1;
this.replace = s2;
this.source = f;
public File resolve() {
File fout = null;
try {
//Create a file object with the file name in the argument:
fout = new File(sourceFile.getName() + "_");
//Open and input and output stream
FileInputStream fis = new FileInputStream(sourceFile);
FileOutputStream fos = new FileOutputStream(fout);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fos));
// The find and replace statements
Pattern p = Pattern.compile(match);
Matcher m = p.matcher(replace);
//Debugging Info
System.out.println("Match value = " + match + " Replace value = " + replace);
//Debugging Complete
String aLine = null;
while((aLine = in.readLine()) != null) {
m.reset(aLine);
//Make replacements
String result = m.replaceAll(replace);
out.write(result);
out.newLine();
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
return fout;If your aim is to learn about regex, then its okay.
Otherwise you might want to check the utility "sed" (stream editor) which does something similar what you are up to. It is a POSIX (.i.e. UNIX) utility, but it is available (in several versions) for other platforms (including Windows) too. (Cf. Cygnus or Mingw). -
Find and replace with multiple files and with a watch folder
I am trying to create a watch folder that uses red_menace script to:
1. Have a folder that receives multiple xml files that run the script one by one.
2. then move the files to an output folder.
I tried modifying the set TheFIle to choose file -- the original text file to:
with multiple selections allowed
But that doesn't seem to work. I know i'm missing a step. Any help is much appreciated!
Thanks!
The way i'd like to setup things is having an input folder on the desktop (or just have the application on the desktop and I can drag the files onto it), and let it do it's thing. Once it's done have it export the xml files into an output folder.
Here's what i got so far:
on open
set TheFIle to choose file -- the original text file
set TheFolder to ("Macintosh HD:Users:user1:Desktop:out") -- the folder for the output file
set TheName to (GetUniqueName for TheFIle from TheFolder) -- the name for the output file
set TheText to read TheFIle -- get the text to edit
set Originals to {"KPCALDATE", "KPCALEVENT", "KPCALDAY", "KPCALBODY", "obituaries name", "" & return & "</cstyle></pstyle>" & return & "<pstyle name=\"obituaries text\"><cstyle>", "<pstyle name=\"obituaries text\"><cstyle name=\"Graphics Bold leadin\" font=\"ADV AGBook-Medium 2\">", "<pstyle name=\"Recipe Ingredients\"><cstyle>", " .com", " .net", " .org", " .edu", "www .", "www. ", "Ho- nolulu", "<pstyle name=\"kicker 12\"><cstyle allcaps=\"1\">fashion news</cstyle><cstyle allcaps=\"1\">" & return & "</cstyle></pstyle>" & return & "", "<component name=\"Headline 1\" type=\"Headline\">" & return & "<header>" & return & "<field name=\"Component name\" type=\"string\" value=\"Headline 1\"/>" & return & "<field name=\"Component type\" type=\"popup\" value=\"Headline\"/>" & return & "</header>" & return & "<body>" & return & "<pstyle name=\"hed STANDARD 36\"><cstyle>", "<pstyle name=\"obituaries text\"><cstyle allcaps=\"1\">", "<pstyle name=\"obituaries text\"><cstyle name=\"Graphics Bold leadin\">", "<pstyle name=\"tagline\"><cstyle>-", "-", "
Per serving:", "<pstyle name=\"Titlebar - mini, red\"><cstyle allcaps=\"1\">NATION & World </cstyle><cstyle allcaps=\"1\">Report</cstyle><cstyle allcaps=\"1\">" & return & "</cstyle></pstyle>" & return & "", "</cstyle></pstyle>"} -- the terms that can be replaced
set Replacements to {"subhed", "subhed", "subhed", "Normal", "obituaries text", ", ", "<pstyle name=\"obituaries text\"><cstyle name=\"Graphics Bold leadin\" font=\"ADV AGBook-Medium 2\">", "<pstyle name=\"Recipe Ingredients\"><cstyle>
", ".com", ".net", ".org", ".edu", "www.", "www.", "Honolulu", "", "<component name=\"Headline1\" type=\"Headline\">" & return & "<header>" & return & "<field name=\"Component name\" type=\"string\" value=\"Headline1\"/>" & return & "<field name=\"Component type\" type=\"popup\" value=\"Headline\"/>" & return & "</header>" & return & "<body>" & return & "<pstyle name=\"hed STANDARD 27\"><cstyle>", "<pstyle name=\"obituaries text\"><cstyle allcaps=\"1\">", "<pstyle name=\"obituaries text\"><cstyle name=\"Graphics Bold leadin\">", "<pstyle name=\"tagline\"><cstyle>", " ", "
Per serving:", "","" & return & "</cstyle></pstyle>"} -- the replacement terms
repeat with AnItem from 1 to count Originals
set TheText to (replaceText of TheText from (item AnItem of Originals) to (item AnItem of Replacements))
end repeat
try -- write a new output file
tell application "Finder" to make new file at TheFolder with properties {name:TheName}
set OpenFile to open for access (result as alias) with write permission
write TheText to OpenFile starting at eof
close access OpenFile
on error errmess
try
log errmess
close access OpenFile
end try
end try
end open
to GetUniqueName for SomeFile from SomeFolder
check if SomeFile exists in SomeFolder, creating a new unique name if needed
parameters - SomeFile [mixed]: a source file path
SomeFolder [mixed]: a folder to check
returns [text]: a unique file name and extension
set {Counter, Divider} to {"00", "_"}
-- get the name and extension
set {name:TheName, name extension:TheExtension} to info for file (SomeFile as text)
if TheExtension is missing value then set TheExtension to ""
set TheName to text 1 thru -((count TheExtension) + 2) of TheName
set NewName to TheName & "." & TheExtension
tell application "System Events" to tell (get name of files of folder (SomeFolder as text))
repeat while it contains NewName
set Counter to text 2 thru -1 of ((100 + Counter + 1) as text) -- leading zero
set NewName to TheName & Divider & Counter & "." & TheExtension
end repeat
end tell
return NewName
end GetUniqueName
to EditItems of SomeItems given Title:TheTitle, Prompt:ThePrompt
displays a dialog for multiple item edit (note that a return is used between each edit item)
for each of the items in SomeItems, a line containing it's text is placed in the edit box
the number of items returned are padded or truncated to match the number of items in SomeItems
parameters - SomeItems [list]: a list of text items to edit
TheTitle [boolean/text]: use a default or the given dialog title
ThePrompt [boolean/text]: use a default or the given prompt text
returns [list]: a list of the edited items, or {} if error
set {TheItems, TheInput, TheCount} to {{}, {}, (count SomeItems)}
if TheCount is less than 1 then return {} -- error
if ThePrompt is in {true, false} then -- "with" or "without" Prompt
if ThePrompt then
set ThePrompt to "Edit the following items:" & return -- default
else
set ThePrompt to ""
end if
else -- fix up the given prompt a little
set ThePrompt to ThePrompt & return
end if
if TheTitle is in {true, false} then if TheTitle then -- "with" or "without" Title
set TheTitle to "Multiple Edit Dialog" -- default
else
set TheTitle to ""
end if
set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set {SomeItems, AppleScript's text item delimiters} to {SomeItems as text, TempTID}
set TheInput to paragraphs of text returned of (display dialog ThePrompt with title TheTitle default answer SomeItems)
repeat with AnItem from 1 to TheCount -- pad/truncate entered items
try
set the end of TheItems to (item AnItem of TheInput)
on error
set the end of TheItems to ""
end try
end repeat
return TheItems
end EditItems
to replaceText of SomeText from OldItem to NewItem
replace all occurances of OldItem with NewItem
parameters - SomeText [text]: the text containing the item(s) to change
OldItem [text]: the item to be replaced
NewItem [text]: the item to replace with
returns [text]: the text with the item(s) replaced
set SomeText to SomeText as Unicode text -- TID's are case insensitive with Unicode text
set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, OldItem}
set {ItemList, AppleScript's text item delimiters} to {text items of SomeText, NewItem}
set {SomeText, AppleScript's text item delimiters} to {ItemList as text, TempTID}
return SomeText
end replaceText
Message was edited by: gamebreakersWhen you use the open or adding folder items to handlers, you need to add the parameters for the file items passed to them.
I'll go ahead and post the applet/droplet version of my original script from the previous topic for reference:
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px; height: 340px;
color: #000000;
background-color: #FFEE80;
overflow: auto;"
title="this text can be pasted into the Script Editor">
-- search and replace multiple items applet/droplet/folder action
-- the terms to replace - edit as needed
property EditableItems : {¬
"one", ¬
"two", ¬
"three", ¬
"four", ¬
"five", ¬
"six", ¬
"seven", ¬
"eight", ¬
"nine", ¬
"ten", ¬
"eleven", ¬
"twelve", ¬
"thirteen", ¬
"fourteen", ¬
"fifteen", ¬
"sixteen", ¬
"seventeen", ¬
"eighteen", ¬
"nineteen", ¬
"twenty"}
-- the folder for the output file(s) - change as needed
property TheFolder : (path to desktop)
property LastEditItems : EditableItems
on run
the applet/droplet was double-clicked
open (choose file with multiple selections allowed)
end run
on open TheItems
items were dropped onto the applet/droplet
parameters - TheItems [list]: a list of the items (aliases) dropped
returns nothing
repeat with AnItem in TheItems
ReplaceMultipleItems from AnItem
end repeat
end open
on adding folder items to this_folder after receiving these_items
folder action - items were added to a folder
parameters - this_folder [alias]: the folder added to
these_items [list]: a list if items (aliases) added
returns nothing
repeat with AnItem in these_items
ReplaceMultipleItems from AnItem
end repeat
end adding folder items to
to ReplaceMultipleItems from SomeFile
replace multiple text items in SomeFile
parameters - SomeFile [alias]: the file to replace items in
returns nothing
set TheName to (GetUniqueName for SomeFile from TheFolder) -- the name for the output file
set TheText to read SomeFile -- get the text to edit
set Originals to (choose from list EditableItems default items LastEditItems with prompt "Select the terms to replace:" with multiple selections allowed) -- the specific terms to replace
set LastEditItems to Originals
set Replacements to (EditItems of Originals with Title given Prompt:"Edit the following replacement terms:") -- the replacement terms
repeat with AnItem from 1 to count Originals
set TheText to (ReplaceText of TheText from (item AnItem of Originals) to (item AnItem of Replacements))
end repeat
try -- write a new output file
tell application "Finder" to make new file at TheFolder with properties {name:TheName}
set OpenFile to open for access (result as alias) with write permission
write TheText to OpenFile starting at eof
close access OpenFile
on error errmess
try
log errmess
close access OpenFile
end try
end try
end ReplaceMultipleItems
to GetUniqueName for SomeFile from SomeFolder
check if SomeFile exists in SomeFolder, creating a new unique name if needed
parameters - SomeFile [mixed]: a source file path
SomeFolder [mixed]: a folder to check
returns [text]: a unique file name and extension
set {Counter, Divider} to {"00", "_"}
-- get the name and extension
set {name:TheName, name extension:TheExtension} to info for file (SomeFile as text)
if TheExtension is in {missing value, ""} then
set TheExtension to ""
else
set TheExtension to "." & TheExtension
end if
set {NewName, TheExtension} to {TheName, (ChangeCase of TheExtension to "upper")}
set TheName to text 1 thru -((count TheExtension) + 1) of TheName
tell application "System Events" to tell (get name of files of folder (SomeFolder as text))
repeat while it contains NewName
set Counter to text 2 thru -1 of ((100 + Counter + 1) as text) -- leading zero
set NewName to TheName & Divider & Counter & TheExtension
end repeat
end tell
return NewName
end GetUniqueName
to EditItems of SomeItems given Title:TheTitle, Prompt:ThePrompt
displays a dialog for multiple item edit (note that a return is used between each edit item)
for each of the items in SomeItems, a line containing it's text is placed in the edit box
the number of items returned are padded or truncated to match the number of items in SomeItems
parameters - SomeItems [list]: a list of text items to edit
TheTitle [boolean/text]: use a default or the given dialog title
ThePrompt [boolean/text]: use a default or the given prompt text
returns [list]: a list of the edited items, or {} if error
set {TheItems, TheInput, TheCount} to {{}, {}, (count SomeItems)}
if TheCount is less than 1 then return {} -- error
if ThePrompt is in {true, false} then -- "with" or "without" Prompt
if ThePrompt then
set ThePrompt to "Edit the following items:" & return -- default
else
set ThePrompt to ""
end if
else -- fix up the given prompt a little
set ThePrompt to ThePrompt & return
end if
if TheTitle is in {true, false} then if TheTitle then -- "with" or "without" Title
set TheTitle to "Multiple Edit Dialog" -- default
else
set TheTitle to ""
end if
set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set {SomeItems, AppleScript's text item delimiters} to {SomeItems as text, TempTID}
set TheInput to paragraphs of text returned of (display dialog ThePrompt with title TheTitle default answer SomeItems)
repeat with AnItem from 1 to TheCount -- pad/truncate entered items
try
set the end of TheItems to (item AnItem of TheInput)
on error
set the end of TheItems to ""
end try
end repeat
return TheItems
end EditItems
to ReplaceText of SomeText from OldItem to NewItem
replace all occurances of OldItem with NewItem
parameters - SomeText [text]: the text containing the item(s) to change
OldItem [text]: the item to be replaced
NewItem [text]: the item to replace with
returns [text]: the text with the item(s) replaced
set SomeText to SomeText as text
if SomeText contains OldItem then
set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, OldItem}
try
set {ItemList, AppleScript's text item delimiters} to {text items of SomeText, NewItem}
set {SomeText, AppleScript's text item delimiters} to {ItemList as text, TempTID}
on error ErrorMessage number ErrorNumber -- oops
set AppleScript's text item delimiters to TempTID
error ErrorMessage number ErrorNumber
end try
end if
return SomeText
end ReplaceText
to ChangeCase of SomeText to CaseType
changes the case or capitalization of SomeText to the specified CaseType using Python
parameters - SomeText [text]: the text to change
CaseType [text]: the type of case desired:
"upper" = all uppercase text
"lower" = all lowercase text
"title" = uppercase character at start of each word, otherwise lowercase
"capitalize" = capitalize the first character of the text, otherwise lowercase
returns [text]: the changed text
set SomeText to SomeText as text
if CaseType is not in {"upper", "lower", "title", "capitalize"} then return SomeText
return (do shell script "/usr/bin/python -c \"import sys; print unicode(sys.argv[1], 'utf8')." & CaseType & "().encode('utf8')\" " & quoted form of SomeText)
end ChangeCase
</pre>
Edit: how does the choose from list dialog handle those big strings? I'm guessing not very well - is that why you avoided using them?
Message was edited by: red_menace -
Find Replace from Textfile with regex
Hello.
I'm wondering if anyone knows about an existing script that does a find/replace by list like the script "FindChangeByList.jsx" that comes with every InDesign installation.
This consists of tow parts, the script itself with the functionality and a simple textfile where you have simple one-liners capable of find/replace with regex.
the Textfile:
//FindChangeList.txt
//A support file for the InDesign CS4 JavaScript FindChangeByList.jsx
//This data file is tab-delimited, with carriage returns separating records.
//The format of each record in the file is:
//findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description
//Where:
//<tab> is a tab character
//findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).
//findProperties is a properties record (as text) of the find preferences.
//changeProperties is a properties record (as text) of the change preferences.
//findChangeOptions is a properties record (as text) of the find/change options.
//description is a description of the find/change operation
//Very simple example:
//text {findWhat:"--"} {changeTo:"^_"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all double dashes and replace with an em dash.
//More complex example:
//text {findWhat:"^9^9.^9^9"} {appliedCharacterStyle:"price"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find $10.00 to $99.99 and apply the character style "price".
//All InDesign search metacharacters are allowed in the "findWhat" and "changeTo" properties for findTextPreferences and changeTextPreferences.
//If you enter backslashes in the findWhat property of the findGrepPreferences object, they must be "escaped"
//as shown in the example below:
//{findWhat:"\\s+"}
grep {findWhat:" +"} {changeTo:" "} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all double spaces and replace with single spaces.
grep {findWhat:"\r "} {changeTo:"\r"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all returns followed by a space And replace with single returns.
grep {findWhat:" \r"} {changeTo:"\r"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all returns followed by a space and replace with single returns.
grep {findWhat:"\t\t+"} {changeTo:"\t"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all double tab characters and replace with single tab characters.
grep {findWhat:"\r\t"} {changeTo:"\r"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all returns followed by a tab character and replace with single returns.
grep {findWhat:"\t\r"} {changeTo:"\r"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all returns followed by a tab character and replace with single returns.
grep {findWhat:"\r\r+"} {changeTo:"\r"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all double returns and replace with single returns.
text {findWhat:" - "} {changeTo:"^="} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all space-dash-space and replace with an en dash.
text {findWhat:"--"} {changeTo:"^_"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all dash-dash and replace with an em dash.
The script:
//FindChangeByList.jsx
//An InDesign CS5.5 JavaScript
@@@BUILDINFO@@@ "FindChangeByList.jsx" 3.0.0 15 December 2009
//Loads a series of tab-delimited strings from a text file, then performs a series
//of find/change operations based on the strings read from the file.
//The data file is tab-delimited, with carriage returns separating records.
//The format of each record in the file is:
//findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description
//Where:
//<tab> is a tab character
//findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).
//findProperties is a properties record (as text) of the find preferences.
//changeProperties is a properties record (as text) of the change preferences.
//findChangeOptions is a properties record (as text) of the find/change options.
//description is a description of the find/change operation
//Very simple example:
//text {findWhat:"--"} {changeTo:"^_"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all double dashes and replace with an em dash.
//More complex example:
//text {findWhat:"^9^9.^9^9"} {appliedCharacterStyle:"price"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find $10.00 to $99.99 and apply the character style "price".
//All InDesign search metacharacters are allowed in the "findWhat" and "changeTo" properties for findTextPreferences and changeTextPreferences.
//If you enter backslashes in the findWhat property of the findGrepPreferences object, they must be "escaped"
//as shown in the example below:
//{findWhat:"\\s+"}
//For more on InDesign scripting, go to http://www.adobe.com/products/indesign/scripting/index.html
//or visit the InDesign Scripting User to User forum at http://www.adobeforums.com
main();
function main(){
var myObject;
//Make certain that user interaction (display of dialogs, etc.) is turned on.
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
if(app.documents.length > 0){
if(app.selection.length > 0){
switch(app.selection[0].constructor.name){
case "InsertionPoint":
case "Character":
case "Word":
case "TextStyleRange":
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
case "Cell":
case "Column":
case "Row":
case "Table":
myDisplayDialog();
break;
default:
//Something was selected, but it wasn't a text object, so search the document.
myFindChangeByList(app.documents.item(0));
else{
//Nothing was selected, so simply search the document.
myFindChangeByList(app.documents.item(0));
else{
alert("No documents are open. Please open a document and try again.");
function myDisplayDialog(){
var myObject;
var myDialog = app.dialogs.add({name:"FindChangeByList"});
with(myDialog.dialogColumns.add()){
with(dialogRows.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Search Range:"});
var myRangeButtons = radiobuttonGroups.add();
with(myRangeButtons){
radiobuttonControls.add({staticLabel:"Document", checkedState:true});
radiobuttonControls.add({staticLabel:"Selected Story"});
if(app.selection[0].contents != ""){
radiobuttonControls.add({staticLabel:"Selection", checkedState:true});
var myResult = myDialog.show();
if(myResult == true){
switch(myRangeButtons.selectedButton){
case 0:
myObject = app.documents.item(0);
break;
case 1:
myObject = app.selection[0].parentStory;
break;
case 2:
myObject = app.selection[0];
break;
myDialog.destroy();
myFindChangeByList(myObject);
else{
myDialog.destroy();
function myFindChangeByList(myObject){
var myScriptFileName, myFindChangeFile, myFindChangeFileName, myScriptFile, myResult;
var myFindChangeArray, myFindPreferences, myChangePreferences, myFindLimit, myStory;
var myStartCharacter, myEndCharacter;
var myFindChangeFile = myFindFile("/FindChangeSupport/FindChangeList.txt")
if(myFindChangeFile != null){
myFindChangeFile = File(myFindChangeFile);
var myResult = myFindChangeFile.open("r", undefined, undefined);
if(myResult == true){
//Loop through the find/change operations.
do{
myLine = myFindChangeFile.readln();
//Ignore comment lines and blank lines.
if((myLine.substring(0,4)=="text")||(myLine.substring(0,4)=="grep")|| (myLine.substring(0,5)=="glyph")){
myFindChangeArray = myLine.split("\t");
//The first field in the line is the findType string.
myFindType = myFindChangeArray[0];
//The second field in the line is the FindPreferences string.
myFindPreferences = myFindChangeArray[1];
//The second field in the line is the ChangePreferences string.
myChangePreferences = myFindChangeArray[2];
//The fourth field is the range--used only by text find/change.
myFindChangeOptions = myFindChangeArray[3];
switch(myFindType){
case "text":
myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
break;
case "grep":
myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
break;
case "glyph":
myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
break;
} while(myFindChangeFile.eof == false);
myFindChangeFile.close();
function myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
//Reset the find/change preferences before each search.
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = NothingEnum.nothing;
var myString = "app.findTextPreferences.properties = "+ myFindPreferences + ";";
myString += "app.changeTextPreferences.properties = " + myChangePreferences + ";";
myString += "app.findChangeTextOptions.properties = " + myFindChangeOptions + ";";
app.doScript(myString, ScriptLanguage.javascript);
myFoundItems = myObject.changeText();
//Reset the find/change preferences after each search.
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = NothingEnum.nothing;
function myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
//Reset the find/change grep preferences before each search.
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences = NothingEnum.nothing;
var myString = "app.findGrepPreferences.properties = "+ myFindPreferences + ";";
myString += "app.changeGrepPreferences.properties = " + myChangePreferences + ";";
myString += "app.findChangeGrepOptions.properties = " + myFindChangeOptions + ";";
app.doScript(myString, ScriptLanguage.javascript);
var myFoundItems = myObject.changeGrep();
//Reset the find/change grep preferences after each search.
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences = NothingEnum.nothing;
function myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
//Reset the find/change glyph preferences before each search.
app.changeGlyphPreferences = NothingEnum.nothing;
app.findGlyphPreferences = NothingEnum.nothing;
var myString = "app.findGlyphPreferences.properties = "+ myFindPreferences + ";";
myString += "app.changeGlyphPreferences.properties = " + myChangePreferences + ";";
myString += "app.findChangeGlyphOptions.properties = " + myFindChangeOptions + ";";
app.doScript(myString, ScriptLanguage.javascript);
var myFoundItems = myObject.changeGlyph();
//Reset the find/change glyph preferences after each search.
app.changeGlyphPreferences = NothingEnum.nothing;
app.findGlyphPreferences = NothingEnum.nothing;
function myFindFile(myFilePath){
var myScriptFile = myGetScriptPath();
var myScriptFile = File(myScriptFile);
var myScriptFolder = myScriptFile.path;
myFilePath = myScriptFolder + myFilePath;
if(File(myFilePath).exists == false){
//Display a dialog.
myFilePath = File.openDialog("Choose the file containing your find/change list");
return myFilePath;
function myGetScriptPath(){
try{
myFile = app.activeScript;
catch(myError){
myFile = myError.fileName;
return myFile;
This is a very useful and easy to maintain script which even people who cant write scripts (but know how to use regex) can do complex search replace mass replacements.
Would love to find something like this for FrameMaker 12 (as i can't write scripts myself).
regards
danielI have visited that site. The first item in the external link says: "You can also configure Firefox to automatically search for text when you type any characters outside of a text field. When typing in a text field these characters should show up in the text field and not trigger the Quick Find bar. "
What I am looking for is the exact opposite. Once my first search is entered in the text box, and the info comes back, I want to start typing the next symbol, and have it automatically show up in the text box, not the Quick Find box. That is how it was working up until a couple of months ago. -
How to find and replace multiple cells at a time
I am doing repetitive work re find text in numbers but then replace following cells with text. How can I find and replace multiple cells at a time?
i.e. doing my own budget spreadsheet and coding all transactions with description and codeDid you try the "Find/Replace" dialog box?:
Then click the "Replace All" button in the bottom left. -
I no longer have access to system folders that allow me to remove old or incorrect PAGES templates. Need to find out how to do that. The only way I can do it now is to blank the template and replace the unwanted template with a blank. It was previously possible to go to MY TEMPLATES and remove the unwanted templates. I don't if this issue is before or since installation of 10.8 (a nightmare in my case, which led to significant failure issues). And because I haven't tried to remove templates since finally managing to install 10.8 (now at 10.8.4), I don't know if this is typical of the newer OS or a problem. I've been a Mac user for more than 25 years, but I think I'm nearing the end of the road. By the way, I've never needed to do this before because the manuals always offered an answer... they don't seem to do that anymore. In any case, I don't know how this works... I'd prefer an email reply if that's possible. But that would probably be too easy, and I don't know how to get a reply.
Thanks, I appreciate the help. I think this is one of the problems Apple is creating by changing the OS so often. I had fomer colleagues at [a major aerospace contractor] who told me that so many original files were ultimately lost because of the deadly change in the "Save As" operation that they are now afraid of every OS update. Apple has badly damaged their support base with that very prominent company (they won't update now until they've fully examined and understand changes in the pre-conditioned nature of OS computer functions), and they are a whole lot less enthaled with Mac-related equipment/software. Can't blame them, I too used orginal files that way (as easy-to-use templates), and lost some important files before I realized what was happening (to late to revert). Companies should not have to retrain employees each time an OS gets an update, it's can be very expensive several different ways. They learned a painful lesson with that one. And because I'm now retired and don't use multiple devices, I need iCloud like I need a hole in the head... but I'm told there's no way to keep Apple out of my computer. Fortunately, because of major problems when initially installing Mountain Lion, one hold-over of the hardware/software damage I experienced was that iCloud can no longer access my computer even though everything else is working fine again. That was the only "good luck" I had as a result of that expensive nightmare.
-
It seems that many (if not all) of my files have been replaced by older versions. I can find the multiple version including the most recent version using the Search, however, they show up in the same directory even though Finder only shows a single copy. I am able to save and then overwrite in order to restore but this is strange. There is no chance that another user here has done any sort of system restore action (at least intentionally).
I can find the multiple version including the most recent version using the Search, however, they show up in the same directory even though Finder only shows a single copy.
In a OS Extended (HFS) file system there is no way you can have two files with identical names in the same directory.
Of course who knows what spotlight is thinking of most of the time when it does its stupid searches (get Find any File instead) and lists its results? Are you sure it is listing the same directory or do you have a backup and it is finding it there and you aren't noticing it is two different volumes?
You could also try reindixing the volume. Add it to the Spotlight system preferences Privacy and then remove it. -
Find and Replace multiple line PHP comment
Greeting everyone!
Hopefully this question is asked in the right place.
I have about 300 php files that have multiple line PHP
comment that start with /* and end with this */. I want to remove
all the comments since I am trying to reduce the file size as much
as possible. The comments are no longer needed and I have tried
many different configureation in the dreamweaver find and replace,
but for the life of me I cannot seem to get it to work. I even
tried useing regular expressions, but the astrick * is a wild card
the the code tags contain an astrick.
Is it possible to do this in dreamweaver, or will I need to
hand edit every page?
Thank for help
exampleI am not sure of the exact syntax but open the find replace
function on a page and play with find syntax search feature from
the drop down menu . If I am not mistaken you should be able to to
search from the beginning of a comment tag to the end of one and
grab whats in between. From the help file
Use the Find And Replace dialog box to search for text or
tags in a document, and to replace the found material with other
text or tags.
Select Edit > Find And Replace.
In the Search pop‑up menu, select Specific Tag.
Select a specific tag or [any tag] from the pop‑up menu
next to the Search pop‑up menu, or type a tag name in the
text box.
(Optional.) Limit the search with one of the following tag
modifiers:
With Attribute Specifies an attribute that must be in the tag
for it to match. You can specify a particular value for the
attribute or select [any value].
Without Attribute Selects an attribute that must not be in
the tag for it to match. For example, select this option to search
for all img tags with no alt attribute.
Containing Specifies text or a tag that must be contained
within the original tag for it to match. For example, in the code
<b><font size="4">heading 1</font></b>, the
font tag is contained within the b tag.
Not Containing Specifies text or a tag that must not be
contained within the original tag for it to match.
Inside Tag Specifies a tag that the target tag must be
contained in for it to match.
Not Inside Tag Specifies a tag that the target tag must not
be contained in for it to match.
(Optional.) To limit the search further, click the Plus (+)
button and repeat step 3.
If you didn’t apply any tag modifiers in steps 3 and 4,
then click the Minus (-) button to remove the tag modifiers
pop‑up menu.
If you want to perform an action when the tag is found (such
as removing or replacing the tag), select the action from the
Action pop‑up menu and, if applicable, specify any additional
information necessary to perform the action. -
I had to replace my Iphone 5c with a new one. Now, my windows 7 pc does not recognize my iphone. Reinstalled itunes. Apple mobile device is running. I did whatever I could find on the internet still no luck. Any suggestions? Thnx
You have done everything verbatim included with this link?
http://support.apple.com/kb/ts1538
Maybe you are looking for
-
All BAPIs related to a Business Object
Hi All, Is there any way by which we can search for all the BAPIs related to a particular Business Object? For ex. can we write a report prgram through which we can search for BAPIs related to a Business Object. Any pointers in this regard would real
-
Images in Canvas Distored - Odd Error?
Oh great and wise FCP ones. Why would my Canvas window in FCP be showing images/clips with green, diagonal crossbars and has the image of a yellow exclamation point on top indicating an odd error? I took a snapshot, figured this would make things sim
-
Broadcasting reports with navigation status
Hi all, We have a problem with broadcasting reports via the Portal in NW2004s. We have scheduled settings including "Navigation Status" and scheduled these reports to be sent as pdf files in an email to different users. This has worked fine until a c
-
Nokia 9500 Media Files Problems
Hello every one Hope you can find some solution for me. here is my problem when I recieve a media file through Bluetooth it will open but when I save it some times it will open for some days then it won`t open and some other times once I saved it sho
-
CPU usage reaches 100 %
I took a screenshot from my jvisualvm. My CPU goes up to 100% in Linux 64 bit and sometimes it goes down back to 10% (mostly just stay at 100%). Can someone check for me where the problem might be ? [http://img156.imageshack.us/img156/5078/screenshot