Dec 29, 2004 11:58:00
I want to write a function to process my own UBB code, so (ignore spaces)
[ I M G ] myImage.gif [ / I M G ] Would change to the html for an image. However the regular expression for replacing square brackets seems not to have been thought about. Below is some quick code that outlines what i want to do and the problem. Shove it in a JSP page: <%! String foo = "[img]"; %> <%! String result = ""; %> <%= foo %> <% result = foo.replaceAll("[img]","-"); %> <%= result%> And the output is [---] So it is not replacing the '[' and ']' . This I understand is because '[' and ']' are used in regular expressions. However one cannot escape them because an error is thrown: illegal escape character What to do? [ December 29, 2004: Message edited by: Jack Wootton ]
Dec 29, 2004 12:06:00
you try \[IMG\]
Dec 29, 2004 12:26:00
Still, illegal escape character
, Ranch Hand
Dec 29, 2004 12:37:00
I think what you have to do is escape the \ chacter so the expression should be:
\\[IMG\\] The reson for the illegal escape character is Java doesn't understand \[
Dec 29, 2004 12:38:00
It worked. Thank you.
Dec 29, 2004 12:56:00
Not really JSP-related, so even though resolved I'm moving this along so it can be available for future reference in a more appropriate forum.
Wink, wink, nudge, nudge, say no more ...
This thread has been viewed 793 times.
All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2018 11:14:51.