Java regex

Andrew Reid andrew.reid at plug.cx
Sun Jun 5 23:26:18 CST 2005


I'm sure this is dead simple, but I can't see it for the life of me.  
Never was any great shakes at regexes...

I've got a little servlet that's meant to do a search-and-replace on  
HTML files. Specifically, it's meant to replace the src attribute of  
the img tag.

So, something like:

<img src="myimage.jpg">

... becomes

<img src="/SendImageServlet?file=/path/to/myimage.jpg">

The problem that I'm encountering at the moment is that the slashes  
are being treated by the regex engine as an escape statement. That  
gives me results like:

<img src="/SendImageServlet?file=pathtomyimage.jpg">

In other words, it's taking the slashes to be escape commands. I'm  
just using the replaceAll method from the String class:

fileContents.replaceAll("src=\"", "src=\"SendFile?file=" + basePath);

How'd you recommend I go about this?

Cheers,

    - andrew

--
| Andrew Reid [andrew.reid at plug.cx]
| Overworked and Underpaid Network Monkey
| C: +61-401-946-813  F: +61-8-8338-2518




More information about the linuxsa mailing list