Skip to main content
Inspiring
April 18, 2013
Answered

Regular Expression For Dreamweaver

  • April 18, 2013
  • 2 replies
  • 1641 views

I still haven't had the time to really become a professional when it comes to regular expressions, and sadly I am in need of one an finding it difficult to wrap my head around.

In a text file I have hundreds of instances like the following:

{Click here to visit my website}{http://www.adobe.com/}

I need a regular expression for Dreamweaver that I can run within the "Find and Replace" window to switch the order of the above elements to:

{http://www.adobe.com/}{Click here to visit my website}

Can anyone provide some guidance? I'm coming up short due to my lack of experience with regular expressions.

Thank you in advance!

This topic has been closed for replies.
Correct answer Steve Sommers

For Dreamweaver:

Search: {([^}]*)}{([^}]*)}

Replace: {$2}{$1}

2 replies

Legend
April 18, 2013

I assume the http links are different, but is "Click here to visit my website" consistent or does this change as well?

Inspiring
April 19, 2013

Steve,

Yes, the links are different, and may not all be HTTP links. Basically I just need to swap whatever is within the first set of brackets with what is in the second set.

For example:

{john}{charlie}

Would become:

{charlie}{john}

Steve SommersCorrect answer
Legend
April 19, 2013

For Dreamweaver:

Search: {([^}]*)}{([^}]*)}

Replace: {$2}{$1}

Participating Frequently
April 18, 2013

So you have a string that starts { and goes until the first }.  Then you have another string exactly the same.  And you want to swap them.  I'm not making any assumption that the second one has to look like a URL (that's a whole other minefield, but perhaps you could do something simple like it must start with http). 

You don't specify how your text file is divided up, have you got this as a complete line to itself, or is it just  a huge block of text?  Preferably as individual lines.

I don't have Dreamweaver, but this worked for me in Notepad++

Find: ^{(.*?)}{(.*?)}$

Replace with: {\2}{\1}

My file looked like this:

{Click here to visit my website}{http://www.adobe.com/}

{some other site}{http://www.example.com/foo}

And doing a Replace All ended up like this:

{http://www.adobe.com/}{Click here to visit my website}

{http://www.example.com/foo}{some other site}

Inspiring
April 19, 2013

Thank you Duncan, but I can't seem to get this to work in Dreamweaver or Notepad++.