Re: String.replaceAll won't work :s

From: Passero (bla_at_bla.bla)
Date: 07/01/04


Date: Thu, 01 Jul 2004 11:10:52 GMT


"Stefan Waldmann" <stefan.k.waldmann@vr-web.de> schreef in bericht
news:2ki9d8F2ltuiU3@uni-berlin.de...

> Hello,
>
> the String#replaceAll(...) method expects a regular expression (regex)
> as first parameter. In regular expressions the "\" has also escape
> function (just like in java Strings). Thus, a regex you would write "\\"
> to match a single "\". But because in java you also have to write "\\"
> to get a single "\" inside the String, what you have to use is "\\\\".
>
> So this should do what you want to achieve:
>
> myString = myString.replaceAll("\\\\","\\\\");
>
> Not kidding! The second parameter is no regex, but only the String which
> should replace all matches of the first param. Try it.
>

Yeah thanks it works but as a second parameter i had to give "////////"
instead of "////"
Very strange but i tried it and when i use "////" as second parameter, he
doesn't change anything.

>
>
> Greetings, Stefan

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.600 / Virus Database: 381 - Release Date: 28/02/2004


Relevant Pages

  • Re: String.replaceAll wont work :s
    ... > Passero wrote: ... > Not kidding! ... The second parameter is no regex, ... Sorry, I was wrong, the second argument seems to be a regex too (just ...
    (comp.lang.java.help)
  • Re: Fastest way to search a string for the occurance of a word??
    ... but the OP's question was what's the "Fastest way to search a string ... in all the tests I did here, the Regex was by far superior. ... However, of course, if you've got new regular expressions all ... Sure - but just that extra Match object could be relevant if the search ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: regular expression help
    ... Basically because if you remove everything that is optional in the regex below you end up with an empty regex: ... So the regex engine will try to match on every character in the string: ... , comma doesn't match, but the nothingness in front of it does. ... A quote followed by any sequence of characters that is not a quote, ...
    (microsoft.public.dotnet.framework)
  • Re: Regex optimization
    ... I was hoping that someone with knowledge of the Regex engine could ... match per string for either Regex. ... reluctant modifier, may be slower .*?, +? ... Variable parts will try to capture as much as possible. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Regex Capture problem
    ... "learned" my regex using a freeware utility that had slightly different ... was trying to capture instead of. ... I have used Regex utilities before, so I understand the concepts of text ... Function RESub(str As String, SrchFor As String, ReplWith As String) As String ...
    (microsoft.public.excel.programming)

Loading