Skip navigation
Currently Being Moderated

changeGrep alters selection

Apr 5, 2013 7:45 PM

Tags: #cs5.5_grep

I'm using a grep search to change double spaces to singles, so the find grep string is "  +" (that's two spacebars). And the change string is one spacebar. Works fine and, no, I don't want to use \s because it grabs other chunks of whitespace that should be left alone.

 

The problem is that I want to run this search on the text selected by the user. And then run another find/change after that.

 

But this particular find/change alters the range of the selected text. You would expect it to shorten the selection by the number of extra spaces that it removes, but it seems to be shortening it by more than that..

 

It's baffling because other grep find/change operations seem to honor the original selection. For example, I'm searching for "^\s+" and replacing with "" to eliminate blank paragraphs and spaces at the beginning of paragraphs. It reduces the length of the selection only by the number of spaces it removes. Similarly, I can use an ordinary text find/change to replace double spaces with single spaces, and the selection adjusts properly. But that find change has to be run in a loop, which seems to take a lot longer.

 

I noticed this while writing a script. but the behavior is the same in user interface.

 
Replies
  • Currently Being Moderated
    Apr 6, 2013 2:46 AM   in reply to RobertKyle

    I don't think I'm seeing what you see, or I don't understand the description. My selections still cover the same selections, less any deleted spaces using your query (provided I do a Change All), but you might want to try Find: (?<=\x{0020})\x{0020}+ and Change: "" instead. (That's null, or blank)

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 8, 2013 3:10 PM   in reply to RobertKyle

    You need the \x in front of it to tell ID it's lookinf for a hex code, though...

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 26, 2013 7:20 AM   in reply to RobertKyle

    It happens in your sample text here, too, now, but so far ONLY when the selection includes the last character of the last paragraph of the story that conatins text. It happens even if there are empty paragrapgs following.

     

    Not sure if that's helpful, but I think it probably means there's some sort of bug at work.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 26, 2013 7:51 AM   in reply to RobertKyle

    have you tried  +?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 26, 2013 7:52 AM   in reply to Eugene Tyson

    that should be [space][space]+?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points