Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search and replace characters

Status
Not open for further replies.

justride

Programmer
Jan 9, 2004
251
US
Hi,

I'd like to know if its possible to search and replace characters in a html file only if the fall within another criteria.

For example, I want to change \ slashes to / slashes but only for html links.

Thanks
 
Do you mean using CSS? Or opening the file in some other setting (Perl, PHP, ASP, etc) and changing it there?

Perl is very good for string manipulation if that is what you want -- you might want to take a look.

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
Yes... something like (in perl
Code:
while (<HTMLFILE>)
{
  $newline = s/<a[[^"]+"[^\\]*[(\\)[^\/]*]]*/\//gi;
  print NEWFILE $newline;
}

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
Thanks for the responses.

I have 1000 html files, all pretty short. Id like to execute some script or something like above, on all files to replace all the \ slashes in the links to /slashes.

somebody created a site with all links to documents, thats hosted on a windows server. it now needs to be compatible with linux. thanks guys!
 
how can i tell the textpad to only replace if the slash is a link, between the <ahref= tags?
thanks
chris
 
EditPlus will let you open the files and run a Find/replace on all the files.


Try expanding the criteria when looking for the text to replace. Regular Expressions will let you look for something conditionally.

Replace slashes that sit AFTER "HREF" and stop replacing them up until the next ">" character.

- Web design and ranting
- Day of Defeat gaming community
"I'm making time
 
If you are uploading to a *nix box then you want to look at the programs awk and sed... both are built to do that exsact thing....

If in Windows, there is a windows version of Emacs -- and emacs has a great Regular expression matching search... Though you would have to open each file in emacs...

In anycase this isn't really isn't an HTML question anylonger -- try posting it in a windows scripting/marcos or unixscipting forum....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top