?
Solved

Adobe Dreamweaver regular expression to replace a filename

Posted on 2013-12-13
7
Medium Priority
?
530 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 750 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 750 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

771 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