Solved

Adobe Dreamweaver regular expression to replace a filename

Posted on 2013-12-13
7
489 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
  • 3
  • 3
7 Comments
 
LVL 74

Expert Comment

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

Author Comment

by:orerockon
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:orerockon
Comment Utility
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 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now