Menu

#8 SE replaceAll doesn't work correctly with regex & wholeWord

closed-fixed
Other (7)
5
2010-05-13
2010-05-07
No

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!

Discussion

  • Robert Futrell

    Robert Futrell - 2010-05-07

    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.

     
  • Christian Rösch

    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!

     
  • Robert Futrell

    Robert Futrell - 2010-05-13
    • status: open --> pending
     
  • Robert Futrell

    Robert Futrell - 2010-05-13

    This should be fixed as of revision 194 in Subversion. Please try it out and let me know if it isn't.

     
  • Christian Rösch

    Yes it seems to be fixed. Thanks!

     
  • Christian Rösch

    • status: pending --> open
     
  • Robert Futrell

    Robert Futrell - 2010-05-13
    • status: open --> closed-fixed
     
  • Robert Futrell

    Robert Futrell - 2010-05-13

    Sounds great. I'm closing this one. Folks can either grab it from SVN or wait for the next official release.