Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38110
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: regex replaceAll? |
| Date | 2018-03-02 20:15 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrnp9jc7f.5mg.avl@logic.at> (permalink) |
| References | (4 earlier) <8c677118-8115-409d-8d3b-396e54b063ae@googlegroups.com> <slrnp9gvpc.5mg.avl@logic.at> <5e445e98-76e9-4feb-9955-035a6c5a2ed5@googlegroups.com> <slrnp9j3ev.5mg.avl@logic.at> <9730d36c-f472-4b7f-9edb-deedc1630868@googlegroups.com> |
Eric Douglas <e.d.programmer@gmail.com> wrote:
> Nope, see what I mean? Apparently not intuitive.
> out = in.replaceAll("(?<=\\G[^b]*b[^b]*)b", "_");
> still getting output exactly the same as the input.
It really seems to me now as if Java (1.8.0_131 here) was just buggy here:
"abaabaaabaaaabaaaaabaaaaaabxbb".replaceAll( "(?<=\G[^b]*b[^b]*b[^b]*)b", "_");
works, while
"abaabaaabaaaabaaaaabaaaaaabxbb".replaceAll( "(?<=\G[^b]*b[^b]*)b", "_");
doesn't.
The apparent "pattern" is, that adding "b[^b]*" will alternate between
working and not working.
Using {2} in a (?<=...) doesn't seem to work at all --
"Look-behind group does not have an obvious maximum length ..."
Anyway:
out = in.replaceAll( "([^b]*b[^b]*)[b]" , "$1_");
seems to work just fine, and:
out = in.replaceAll( "([^b]*(b[^b]*){2})b" , "$1_");
only replaces every third b.
Imho, that's one STRONG argument for the simpler approach.
>> Well, nope. if you do a "ababab".replaceAll("b","_"); you'd
>> want all "b"s replaced, even if not adjacent to the previous
>> one.
> Maybe it's just me, but "end of previous" was not clear.
> If you're search the "ababab" string and you're looking for "bab"
> can it find it twice?
Nope, but in "babababa", if you search for \\Gbab you'll get only
one match, because the second match is not adjacent to the first one.
Without the \\G, the next match *may* still start adjacent ("babbab"),
but *may* also start later ("babxyzbab").
Under no circumstances(*) will the second match overlap a previous one.
*: except, of course, when Java's RE impl is buggy. Then all bets are off.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
regex replaceAll? Eric Douglas <e.d.programmer@gmail.com> - 2018-03-01 06:19 -0800
Re: regex replaceAll? Andreas Leitgeb <avl@logic.at> - 2018-03-01 19:03 +0000
Re: regex replaceAll? Eric Douglas <e.d.programmer@gmail.com> - 2018-03-01 12:15 -0800
Re: regex replaceAll? Daniele Futtorovic <da.futt.news@laposte.net> - 2018-03-01 21:51 +0100
Re: regex replaceAll? Eric Douglas <e.d.programmer@gmail.com> - 2018-03-01 13:36 -0800
Re: regex replaceAll? Arne Vajhøj <arne@vajhoej.dk> - 2018-03-01 16:59 -0500
Re: regex replaceAll? Andreas Leitgeb <avl@logic.at> - 2018-03-01 21:55 +0000
Re: regex replaceAll? Eric Douglas <e.d.programmer@gmail.com> - 2018-03-01 14:00 -0800
Re: regex replaceAll? Andreas Leitgeb <avl@logic.at> - 2018-03-01 22:31 +0000
Re: regex replaceAll? Arne Vajhøj <arne@vajhoej.dk> - 2018-03-01 17:52 -0500
Re: regex replaceAll? Andreas Leitgeb <avl@logic.at> - 2018-03-02 00:14 +0000
Re: regex replaceAll? Kiwi User <martin@mydomain.invalid> - 2018-03-02 00:43 +0000
Re: regex replaceAll? Arne Vajhøj <arne@vajhoej.dk> - 2018-03-01 19:49 -0500
Re: regex replaceAll? Kiwi User <martin@mydomain.invalid> - 2018-03-02 01:33 +0000
Re: regex replaceAll? Arne Vajhøj <arne@vajhoej.dk> - 2018-03-02 13:00 -0500
Re: regex replaceAll? Kiwi User <martin@mydomain.invalid> - 2018-03-03 20:07 +0000
Re: regex replaceAll? Eric Douglas <e.d.programmer@gmail.com> - 2018-03-02 05:40 -0800
Re: regex replaceAll? Andreas Leitgeb <avl@logic.at> - 2018-03-02 17:46 +0000
Re: regex replaceAll? Eric Douglas <e.d.programmer@gmail.com> - 2018-03-02 10:38 -0800
Re: regex replaceAll? Andreas Leitgeb <avl@logic.at> - 2018-03-02 20:15 +0000
Re: regex replaceAll? Eric Douglas <e.d.programmer@gmail.com> - 2018-03-02 12:43 -0800
Re: regex replaceAll? Eric Douglas <e.d.programmer@gmail.com> - 2018-03-02 12:58 -0800
Re: regex replaceAll? Daniele Futtorovic <da.futt.news@laposte.net> - 2018-03-03 00:06 +0100
Re: regex replaceAll? Daniele Futtorovic <da.futt.news@laposte.net> - 2018-03-01 20:29 +0100
Re: regex replaceAll? Daniele Futtorovic <da.futt.news@laposte.net> - 2018-03-01 20:30 +0100
Re: regex replaceAll? Eric Douglas <e.d.programmer@gmail.com> - 2018-03-01 12:28 -0800
Re: regex replaceAll? Daniele Futtorovic <da.futt.news@laposte.net> - 2018-03-01 21:40 +0100
Re: regex replaceAll? Eric Douglas <e.d.programmer@gmail.com> - 2018-03-01 13:52 -0800
Re: regex replaceAll? Daniele Futtorovic <da.futt.news@laposte.net> - 2018-03-02 02:25 +0100
csiph-web