Prev: jsp webhost on internet
Next: Version of JDK to develope the Applet VS version of JRE on client's browser
From: gwoodhouse on 4 May 2010 08:44 Hello, Quick one: I'm trying to remove this from a String: "<![CDATA[" But when using this line it ignores it (Would usually just single escape it but java doesn't like that either): tagContents.replaceAll("<!\\[CDATA\\[", ""); When using this one it throws an execption (With good cause since [ is a regex special character): tagContents.replaceAll("<![CDATA[", ""); Whats your guys suggestion? Graeme
From: Lew on 4 May 2010 09:02 "gwoodho...(a)gmail.com" wrote: > I'm trying to remove this from a String: "<![CDATA[" > > But when using this line it ignores it (Would usually just single > escape it but java doesn't like that either): > tagContents.replaceAll("<!\\[CDATA\\[", ""); > > When using this one it throws an execption (With good cause since [ is > a regex special character): > tagContents.replaceAll("<![CDATA[", ""); > This works for me: <sscce comment="run as a JUnit test"> import org.junit.Test; import static org.junit.Assert.assertEquals; public class RegexTest { @Test public void testRegex() { final String ts = "<![CDATA[This is a test."; final String exp = "This is a test."; final String tx = ts.replaceAll( "<!\\[CDATA\\[", ""); assertEquals( exp, tx ); } } </sscce> So what exactly is your problem? What are you doing that you didn't tell us? You really, really, really, really, really, really, really should provide an SSCCE. Obviously your problem is in the part you are not revealing to us. <http://sscce.org/> -- Lew
From: Eric Sosman on 4 May 2010 09:01 On 5/4/2010 8:44 AM, gwoodhouse(a)gmail.com wrote: > Hello, > > Quick one: > > I'm trying to remove this from a String: "<![CDATA[" > > But when using this line it ignores it (Would usually just single > escape it but java doesn't like that either): > tagContents.replaceAll("<!\\[CDATA\\[", ""); This looks right, and works for me. Just guessing: Do you keep the String that replaceAll() returns, or do you just throw it away (imagining, perhaps, that replaceAll() modifies its own immutable String object)? -- Eric Sosman esosman(a)ieee-dot-org.invalid
From: gwoodhouse on 4 May 2010 09:44 On May 4, 2:01 pm, Eric Sosman <esos...(a)ieee-dot-org.invalid> wrote: > On 5/4/2010 8:44 AM, gwoodho...(a)gmail.com wrote: > > > Hello, > > > Quick one: > > > I'm trying to remove this from a String: "<![CDATA[" > > > But when using this line it ignores it (Would usually just single > > escape it but java doesn't like that either): > > tagContents.replaceAll("<!\\[CDATA\\[", ""); > > This looks right, and works for me. Just guessing: Do you > keep the String that replaceAll() returns, or do you just throw > it away (imagining, perhaps, that replaceAll() modifies its own > immutable String object)? > > -- > Eric Sosman > esos...(a)ieee-dot-org.invalid Thanks all, Literally, i was doing a .replaceAll and then not assigning the return to anything. I'm a bad man. Thanks to Bent C/D
From: Jim Janney on 4 May 2010 11:19 "gwoodhouse(a)gmail.com" <gwoodhouse(a)gmail.com> writes: > Hello, > > Quick one: > > I'm trying to remove this from a String: "<![CDATA[" > > But when using this line it ignores it (Would usually just single > escape it but java doesn't like that either): > tagContents.replaceAll("<!\\[CDATA\\[", ""); > > When using this one it throws an execption (With good cause since [ is > a regex special character): > tagContents.replaceAll("<![CDATA[", ""); > > Whats your guys suggestion? > tagContents.replaceAll(Pattern.quote("<![CDATA["), ""); -- Jim Janney
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: jsp webhost on internet Next: Version of JDK to develope the Applet VS version of JRE on client's browser |