Solved

Adobe Dreamweaver regular expression to replace a filename

Posted on 2013-12-13
7
495 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

770 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