Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Replacing Punctuation

hi all,

Im trying to replace all mentions of .html in a html fine to .jsp. For example if i had:

<html>
<h1>
Some Text Here
</h1>
<a href ="page1.html"> Go to Page1
</html>

i would want to ONLY replace the .html in the link.

By using:

String replace= src.replaceAll(".html", ".jsp");

i succesfully replace the .html in the link but i also replace the html at the start and at the beginning despite them not having a "." in front of them? Any ideas on how to fix this PLEASE
[577 byte] By [Sarah20] at [2007-11-11 8:29:05]
# 1 Re: Replacing Punctuation
Look at the Pattern class, search to match the pattern.

Did you try to use an escape code before the period? ("\.html")
nspils at 2007-11-11 22:35:17 >
# 2 Re: Replacing Punctuation
it should be ("\\.html"), since \ has to be escaped within strings with \\. the dot is the regular expression for anycharacter.
graviton at 2007-11-11 22:36:22 >