Solved

Adobe Dreamweaver regular expression to replace a filename

Posted on 2013-12-13
7
511 Views
Last Modified: 2013-12-15
Hello, I am sure this is answered elsewhere but I can't seem to get my head around regexp and I can't find a specific example for my problem. I need to find and change a file extension and filename for an href tag. Specifically I want to find and replace (in a filename):

"(any subdirectory(/)(specific word)(space)(any words)(period)(extension)" example: "dir/one two.png" to "dir/one two.html" where "dir/" is the subdirectory, "one" is the word one and "two" can be any word or more than one word.

So the result for "dir/one two.png" would be "dir2/one two.html" and "dir/one two three.png" would be "dir2/one two three.html"
0
Comment
Question by:orerockon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39717902
By way of Find/Replace or by way of code?
0
 

Author Comment

by:orerockon
ID: 39718099
Using find in Dreamweaver (Ctrl-F) and selecting use regular expressions. Sorry, I should have said that. I assume (perhaps erroneously) that Dreamweaver uses regular expressions in the same way as other software, so I don't think the solution would be any different in Dreamweaver.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39718149
Unfortunately, you cannot assume that all applications have the same regex support. Each programming language and each text editor has its own regex engine. Sometimes they overlap in functionality; most often they do not.

I don't have DW to test, but an article I found appears to indicate that there is decent regex support. You might try the following:

"(any subdirectory(/)(specific word)(space)(any words)(period)(extension)"

Find
([^/]+/specific-word( [a-zA-Z])+)\.png

Open in new window


Replace
$1.html

Open in new window

0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

Author Comment

by:orerockon
ID: 39718165
Very very close! But I didn't quite explain it right. The subdirectory also has to be a specific word or words. Otherwise it picks up matching filenames with the .png extension in more than one subdirectory. For example I need to specify "Subdirectory A" and exclude (for example) "Subdirectory B". Maybe I am not following your string correctly?
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 39718242
I didn't mean to post your example text in my comment, so I hope that didn't cause confusion.

To have specific words in the subdirectory, just remove the very first part of the pattern before the first slash, and put in your specific word(s):

(specific-word/specific-word( [a-zA-Z])+)\.png

Open in new window

0
 
LVL 9

Accepted Solution

by:
Derek Jensen earned 250 total points
ID: 39720056
Perhaps you might make it a bit simpler (and containing only one capture group) by putting the space inside the brackets:

(specific-word/specific-word[ a-zA-Z]+)\.png

Open in new window

I've also seen a whole host of other chars allowed in a filename, and so you might have better luck with the below regex:

(specific-word/specific-word.+?)\.png

Open in new window

which says, "after finding the specific string of text "specific-word/specific-word", find at least one of *any* character, up to but not including the specific string ".png", and then look for ".png". ;-)
0
 

Author Comment

by:orerockon
ID: 39720222
I have tried the previous suggestion and came up short, there are a whole host of possibilities of directory and file names and it doesn't apply t many of them. I could explain the situation in more detail but I can't do that right now. Unfortunately I have run out of time and I will try again when I do have the time. Thanks for you suggestions, I have saved them in Dreamweaver and I'll try tweaking them later.
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

726 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