Solved

Adobe Dreamweaver regular expression to replace a filename

Posted on 2013-12-13
7
493 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 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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