Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34705
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: String replaceAll escaping sequence |
| Date | 2016-06-24 19:49 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <nkkgv4$hf6$2@gioia.aioe.org> (permalink) |
| References | <aea37416-d56a-4ff7-a2f8-202cd96e3266@googlegroups.com> |
On 6/24/2016 3:31 AM, Philipp Kraus wrote:
> I try to add an escape sequence to a String. I have got String with #, _ & (symbols which
> must be escaped on LaTeX) and try to put a backslash in front of the
symbol, so:
>
> # -> \#
> $ -> \$
>
> I try to do this with:
>
> mystring.replaceAll( "([\\$\\#&%_])", "\\\\$1" )
>
> but in this case i get a double backslash \\$ for example, on
>
> mystring.replaceAll( "([\\$\\#&%_])", "\\$1" )
>
> I don't get any backslash at the output.
>
> How can I create the correct regex to put one backslash in front of the symbol?
The 4 backslashes works here.
String s = "a#b#c";
System.out.println(s.replaceAll("[#]", "\\$0"));
System.out.println(s.replaceAll("[#]", "\\\\$0"));
gives me:
a$0b$0c
a\#b\#c
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
String replaceAll escaping sequence Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-06-24 00:31 -0700
Re: String replaceAll escaping sequence Arne Vajhøj <arne@vajhoej.dk> - 2016-06-24 19:49 -0400
Re: String replaceAll escaping sequence Lew <lewbloch@gmail.com> - 2016-06-25 17:57 -0700
Re: String replaceAll escaping sequence Arne Vajhøj <arne@vajhoej.dk> - 2016-06-25 22:14 -0400
Re: String replaceAll escaping sequence Daniel Pitts <usenet@coloraura.com> - 2016-06-27 13:52 -0700
csiph-web