A different question: indices with ReplaceAll?

Hi everybody,

This is kind of an offshoot of my earlier post, since this has to do with tweaking a decryption program this time, but it's a different question, so I figured I should start a new topic.

Anyway, does anyone know if there's a way to find out which indices in a string were changed when you call replaceAll on a string? I was experimenting with substitution ciphers with a very large alphabet and ran into that problem when the decrypted value of one character was the encrypted value for another. Can anyone help me out with this too?

Thanks for all the help so far,

Jezzica85

[622 byte] By [jezzica85a] at [2007-11-27 11:19:01]
# 1

I'm still learning this myself, but you can get info on regex matches (before replacement) through use of the Pattern and Matcher classes. When I've seen Matcher used, they haven't called a Matcher constructor, but rather obained from a call to PatternObject.matcher(charSequence to search).

petes1234a at 2007-7-29 14:34:21 > top of Java-index,Java Essentials,Java Programming...
# 2

If you look at the source for replaceAll(), you'll see that it works by calling find(), appendReplacement() and appendTail(). You can copy that and add calls to start() and end() after each find() to get the indices of the text that gets replaced.

uncle_alicea at 2007-7-29 14:34:21 > top of Java-index,Java Essentials,Java Programming...
# 3

Cool, thanks. I'll have to check that out.

jezzica85a at 2007-7-29 14:34:21 > top of Java-index,Java Essentials,Java Programming...