search and replace with regular expressions

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
superdez
Forum Commoner
Posts: 33
Joined: Tue Jul 03, 2007 1:36 pm

search and replace with regular expressions

Post by superdez »

How could I replace all the commas with "commas followed by a space" only within the keywords meta tag ? (using dreamweaver's regular expressions)

Turn this:

<meta name="Keywords" content="word1,word2,word3,word4,word5,word6" />

into this:

<meta name="Keywords" content="word1, word2, word3, word4, word5, word6" />


I've tried many combinations but couldn't find answer:
"Keywords" content="[,]/>$
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What regular expression engine does Dreamweaver use?
superdez
Forum Commoner
Posts: 33
Joined: Tue Jul 03, 2007 1:36 pm

Post by superdez »

Adobe says that it uses the JavaScript engine.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not sure how complex you can make the expression(s) or code, but in Javascript (as well as PHP) what I do is write an expression to find the whole tag I want to manipulate first. I then iterate those results finding all "content" attributes. It's a simple replace call after that and some join method calls, typically.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Just copy the tag into a temporary file, do a regular find and replace on it, then paste it back.

Edit: 8O Do my eyes deceive me?
Post Reply