SE replaceAll doesn't work correctly with regex & wholeWord
A syntax highlighting, code folding text component written in Swing
Brought to you by:
robert_futrell
I think there is a problem with the SearchEngine. I just wrote some Test cases and found out that there is a problem.
I wanted to replaceAll() words that are four chars long, but this didn't work as I expected it to do ..
I used this text:
This is only a text that should ensure that regex does work correctly!
Then I replaced all with replaceAll with this settings: replaceAll( ta, "[a-zA-Z]{4}", "TOOT", false, true, true );
I would expect:
TOOT is TOOT a TOOT TOOT should ensure TOOT regex TOOT TOOT correctly!
But this occured:
TOOT is TOOT a TOOT TOOT TOOTld TOOTre TOOT TOOTx TOOT TOOT TOOTTOOTy!
Ahh - so it's not that the regex is being matched incorrectly, but rather that you specified "Match whole word," but that option wasn't honored, correct?
Indeed, I just did a simple test, and it seems that "whole word" is not honored ONLY in the case of "replaceAll()" with regex enabled. Is that what you're seeing as well? regex/"whole word" seem to work fine with find() and replace().
Let me know if you're seeing something different.
Yes, you are absolutely right!
With find() and replace() it works fine but only replaceAll() wasn't right. And I only mean if you're using regex AND whole word!
This should be fixed as of revision 194 in Subversion. Please try it out and let me know if it isn't.
Yes it seems to be fixed. Thanks!
Sounds great. I'm closing this one. Folks can either grab it from SVN or wait for the next official release.